Beispiel #1
0
        public void Init()
        {
            var options = new MyStaging.Metadata.StagingOptions("MySql", ConstantUtil.MYSQL_CONNECTION);
            var context = new MySqlDbContext(options);

            Assert.NotNull(context.User);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //IGeneralFactory factory = new GeneralFactory();
            //factory.CodeFirst(new MyStaging.Metadata.ProjectConfig()
            //{
            //    ConnectionString = "server=127.0.0.1;user id=root;password=root;database=mystaging",
            //    Mode = MyStaging.Metadata.GeneralMode.Db,
            //    OutputDir = @"D:\MyGitHub\mystaging\examples\Mysql\Models",
            //    ProjectName = "Mysql",
            //    Provider = "MySql"
            //});

            var options = new MyStaging.Metadata.StagingOptions("MySql", "server=127.0.0.1;user id=root;password=root;database=mystaging");
            var context = new MysqlDbContext(options);

            var customer = new Customer {
                Name = "好久不见"
            };

            context.Customer.Insert.Add(customer);

            //// 单个查询
            //var article = context.Customer.Select.Where(f => f.Id == 2 && f.Name == "Ron").ToOne();
            //// 列表查询,排序、分页、分组
            //var articles = context.Customer.Select.OrderBy(f => f.Id).Page(1, 10).GroupBy("Name").ToList();
            //// 表连接查询
            //var article = context.Article.Select.InnerJoin<Customer>("b", (a, b) => a.userid == b.Id).Where<Customer>(f => f.Id == 2).ToOne();
            //// 首字段查询,ToScalar 参数可以传递 Sql 参数,比如 SUM(x)
            //var id = context.Customer.Select.Where(f => f.Id == 2 && f.Name == "Ron").ToScalar<int>("Id");
            var a3      = context.Article.Update.SetValue(f => f.content, "未来已来,从这里开始").Where(f => f.id == 1).SaveChange();
            var article = new Article()
            {
                content    = "你是谁?你从哪里来?要到哪里去?",
                createtime = DateTime.Now,
                userid     = customer.Id,
                IP         = "127.0.0.1",
                State      = true,
                title      = "振聋发聩的人生三问"
            };

            var list = new System.Collections.Generic.List <Article>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(article);
            }
            var a2      = context.Article.Insert.Add(article);
            var affrows = context.Article.Insert.AddRange(list).SaveChange();

            Console.WriteLine(affrows);
            // context.Article.Delete.Where(f => f.id == a2.id).SaveChange();

            //    Console.WriteLine(a2.id);

            Console.WriteLine("success.....");
            Console.ReadKey();
        }
Beispiel #3
0
        public void Transaction()
        {
            var options = new MyStaging.Metadata.StagingOptions("MySql", ConstantUtil.MYSQL_CONNECTION);
            var context = new MySqlDbContext(options);

            context.BeginTransaction();
            Assert.Single(context.Trans);
            context.CommitTransaction();
            Assert.Equal(0, context.Trans.Keys.Count);

            context.BeginTransaction();
            Assert.Single(context.Trans);
            context.RollBackTransaction();
            Assert.Equal(0, context.Trans.Keys.Count);
        }