Beispiel #1
0
        public static void Backup()
        {
            var db = DbMocker.NewDataBase();

            //List<UserInfo> list = new List<UserInfo>();
            //for (int i = 0; i < 10; i++)
            //{
            //    var user1 = new UserInfo
            //    {
            //        Name = "NameInsert" + i,
            //        Age = 20 + 16,
            //        DTCreate = new DateTime(1985, 1, 1),
            //        Role = RoleType.经理
            //    };
            //    list.Add(user1);
            //    //db.Insert(user1);
            //}

            ////db.InsertBulk(list);
            //db.InsertBatch(list, new BatchOptions() { BatchSize = 30 });


            BackupOption option = new BackupOption();

            option.BackupExportType = BackupExportType.InsertSQL;
            option.EnableSqlFilter  = false;
            option.SQL = "";// "SELECT * FROM TB_USER WHERE ID >0 AND ID <=10 ORDER BY ID ";
            var result = db.Backup <UserInfo>(option);

            Console.WriteLine(result.ToString());
        }
Beispiel #2
0
        public static void Batch()
        {
            var db    = DbMocker.NewDataBase();
            int total = 0;

            var batch = db.NewBatchCommand(new BatchOptions()
            {
                BatchSize = 3, StatementSeperator = ";"
            });


            string command = "update tb_user2  set name ='sdfdf' where id = 3";

            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));
            batch.AddOrProcess(batch.CreateCommand(command));

            PrintHelper.WriteLine("");
        }
Beispiel #3
0
        public static void InsertBatch()
        {
            var db = DbMocker.NewDataBase();
            //   db.Config.EnableOrmLog = false;
            //  db.Config.EnableDebug = true;
            //     db.Config.Interceptors.Add(new ConnectionTestIntercept());
            //var user1 = new UserInfo
            //{
            //    Name = "NameInsert",
            //    Age = 20 + 16,
            //    DTCreate = new DateTime(1985, 1, 1)
            //};
            //db.Insert(user1);



            List <UserInfo> list = new List <UserInfo>();

            for (int i = 0; i < 100; i++)
            {
                var user1 = new UserInfo
                {
                    Name     = "NameInsert" + i,
                    Age      = 20 + 16,
                    DTCreate = new DateTime(1985, 1, 1),
                    Role     = RoleType.经理
                };
                list.Add(user1);
                //db.Insert(user1);
            }

            db.InsertBulk(list);
            // db.InsertBatch(list, 1000);
        }
Beispiel #4
0
        public static void Convert()
        {
            var db    = DbMocker.NewDataBase();
            int total = 0;

            var pgp       = Predicates.Group(GroupOperator.And);
            var sortGroup = Predicates.SortGroup();

            sortGroup.Add(Predicates.Sort("", false));

            var datapage = db.GetPage <UserInfo>(1, 10, pgp, sortGroup, out total).ToList();

            var list22 = db.ExecuteReader("SELECT * FROM TB_USER ");
            //  var list33 = list22.ToModel<object>();
            var list = db.ExecuteList <object>("SELECT * FROM TB_USER2 ");

            // var list = db.ExecuteReader("SELECT * FROM TB_USER2 ").ToEnumerable<UserInfo>();

            //var Model = db.ExecuteModel<UserInfo>("SELECT * FROM TB_USER2 ");

            //var o = db.ExecuteDictionary<string, int>("SELECT T.NAME, SUM(T.Id) FROM TB_USER T GROUP BY T.NAME");


            PrintHelper.WriteLine(list.Count.ToString());
        }
Beispiel #5
0
        public static void Insert()
        {
            var db = DbMocker.NewDataBase();
            //db.Config.EnableOrmLog = false;
            //db.Config.EnableDebug = true;
            //db.Config.KeepConnectionAlive = true;
            //db.Config.Interceptors.Add(new ConnectionTestIntercept());

            var data1 = db.FluentSqlBuilder.Select <UserInfo>().ExecuteList();

            data1 = db.FluentSqlBuilder.Select <UserInfo>().ExecuteList();

            UserInfo info = new UserInfo();

            info.Age      = 67;
            info.Email    = "*****@*****.**";
            info.Name     = "李威法";
            info.DTCreate = DateTime.Now;
            var ddd = db.Insert <UserInfo>(info, null);


            var user1 = new UserInfo
            {
                Name     = "NameInsert",
                Age      = 20 + 16,
                DTCreate = DateTime.Now
            };

            db.Insert(user1);
            //db.Connection.ExecuteScalarAsync
        }
Beispiel #6
0
        public static void TestOptExt()
        {
            var db = DbMocker.NewDataBase();

            //var one = db.FirstOrDefault<UserInfo>(p => p.Id > 1);
            var one2 = db.Get <UserInfo>(500);
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("Name", "dsfsdfdsf");
            parameters.Add("Age", 33);


            Dictionary <string, object> conditons = new Dictionary <string, object>();

            conditons.Add("Name", "dsfsdfdsf");
            conditons.Add("Age", 33);

            db.InsertByKV <UserInfo>(parameters);

            var count     = db.CountByKV <UserInfo>(conditons);
            var countLong = db.LongCountByKV <UserInfo>(conditons);

            // db.UpdateBySQL("update TB_USER2 set name = 'sdfdfs' where id = 400");
            var dd2 = db.UpdateByKV <UserInfo>(parameters, conditons);

            var dd3 = db.DeleteByKV <UserInfo>(conditons);


            var o = db.DeleteById <UserInfo>(500);

            db.DeleteByIds <UserInfo>("Id", " 1,2,3");
        }
Beispiel #7
0
        public async static void InsertBatch()
        {
            //var table = new DataTable("Batcher");
            //table.Columns.Add("Id", typeof(int));
            //table.Columns.Add("Name1", typeof(string));
            //table.Columns.Add("Name2", typeof(string));
            //table.Columns.Add("Name3", typeof(string));
            //table.Columns.Add("Name4", typeof(string));

            ////构造100000条数据
            //for (var i = 0; i < 100000; i++)
            //{
            //    table.Rows.Add(i, i.ToString(), i.ToString(), i.ToString(), i.ToString());
            //}

            var db = DbMocker.InstanceDataBase();
            ////db.InsertBatch(table, new BatchOptions() { BatchSize=10000});
            //db.InsertBulk(table);

            var list = new List <UserInfo>();

            for (var i = 0; i < 1000; i++)
            {
                list.Add(new UserInfo()
                {
                    Id = i, Name = "Jesica-" + i, Age = 88, DTCreate = DateTime.Now, Email = i.ToString(), Role = RoleType.普通用户, HasDelete = false, StatusCode = 1
                });
            }

            //await db.InsertBulkAsync(list);
            await db.InsertBatchAsync(list);
        }
Beispiel #8
0
        //public static void PetapocoNormal(int takeCount)
        //{
        //    using (var petapoco = new PetaPoco.Database(DbHelper.ConnectionString, "System.Data.SqlClient"))
        //    {
        //        petapoco.OpenSharedConnection();
        //        var list = petapoco.Fetch<UserInfo>(string.Format("select top {0} * from TB_USER", takeCount.ToString()));

        //    }


        //}
        //public static void PetapocoFast(int takeCount)
        //{
        //    using (var petapoco = new PetaPoco.Database(DbHelper.ConnectionString, "System.Data.SqlClient"))
        //    {
        //        petapoco.OpenSharedConnection();
        //        petapoco.EnableAutoSelect = false;
        //        petapoco.EnableNamedParams = false;
        //        petapoco.ForceDateTimesToUtc = false;
        //        var list = petapoco.Fetch<UserInfo>(string.Format("select top {0} * from TB_USER", takeCount.ToString()));

        //    }


        //}

        //public static void OrmLiteNormal(int takeCount)
        //{

        //    OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance; //Using SQL Server
        //    var c = DbHelper.CreateConnection();
        //    c.Close();
        //    IDbCommand ormLiteCmd = c.CreateCommand();
        //    ormLiteCmd.Select<UserInfo>(string.Format("select top {0} * from TB_USER", takeCount.ToString()));

        //}

        //public static void SimpleDataFast(int takeCount)
        //{
        //    // Simple.Data
        //    var sdb = Simple.Data.Database.OpenConnection(DbHelper.ConnectionString);

        //    IEnumerable<dynamic> d = sdb.UserInfo.All();
        //    var data = d.Take(takeCount);



        //}

        public static void Page()
        {
            var db    = DbMocker.NewDataBase();
            int total = 0;
            var list  = db.GetPageByWhere <UserInfo>(1, 5, "Age > 10", "", out total);

            PrintHelper.WriteLine(total + "=" + list.Count());
        }
Beispiel #9
0
        static void PureDataQueryTest(int takeCount)
        {
            var db = DbMocker.InstanceDataBase().OpenSharedConnection();

            db.Config.EnableOrmLog    = false;
            db.Config.EnableDebug     = false;
            db.Config.EnableIntercept = false;
            var list = db.QueryBySQL <UserInfo>(string.Format("select top {0} * from TB_USER", takeCount.ToString())).ToList();
        }
Beispiel #10
0
        public static void QueryMutil()
        {
            var    db       = DbMocker.NewDataBase();
            string sqlDemo1 = @"SELECT * FROM TB_USER AS u WHERE u.Id=@UserId 
                                SELECT * FROM TB_USER AS ui WHERE ui.Id=2";

            using (var multi = db.GetMultiple(sqlDemo1, new { UserId = 1 }))
            {
                var user     = multi.Read <UserInfo>().FirstOrDefault();
                var userinfo = multi.Read <UserInfo>().FirstOrDefault();
            }
        }
Beispiel #11
0
        static void ConstructTest()
        {
            var db1 = DbMocker.NewDataBase();

            db1.EnsureOpenConnection();
            //PrintHelper.WriteLine(db1.Connection?.State + "=" + db1.GetHashCode());
            for (var b = 0; b < 50; b++)
            {
                //Task task = new Task( () => {
                var db = DbMocker.NewDataBase();
                // db.EnsureOpenConnection();
                var list3 = db.ExecuteScalar <int>("select id from tb_user where id = 1");   //.ExecuteReader("select * from tb_user").ToList<UserInfo>();// db.Query<UserInfo>().ToList();
                var ddd   = db.Get <UserInfo>(1);
                //}
                //PrintHelper.WriteLine(db.Connection?.State + "=" + db.GetHashCode());
                //});
                //task.Start();
            }


            //Task.Factory.StartNew(() =>
            //{
            //    using (var db = DbMocker.NewDataBase())
            //    {
            //        var list = db.ExecuteScalar("select 1 from tb_user");// db.Query<UserInfo>().ToList();

            //        var db1 = DbMocker.NewDataBase();
            //        int total = 0;
            //        var list2 = db1.GetPageByWhere<UserInfo>(1, 5, "Age > 10", "", out total).ToList();
            //        var db2 = DbMocker.NewDataBase();

            //        var list3 = db2.ExecuteScalar("select 1 from tb_user");//.ExecuteReader("select * from tb_user").ToList<UserInfo>();// db.Query<UserInfo>().ToList();

            //        db2.Close();

            //        db1.Close();

            //        db.Close();

            //    }


            //});


            //
            //System.Threading.Thread.Sleep(500);


            //var db = DbMocker.NewDataBase();
            // var db = DbMocker.InstanceDataBase().OpenNewConnection();
        }
Beispiel #12
0
        public static void Insert()
        {
            var db = DbMocker.NewDataBase();
            //db.Config.EnableOrmLog = false;
            //db.Config.EnableDebug = true;
            //db.Config.Interceptors.Add(new ConnectionTestIntercept());
            //var user1 = new UserInfo
            //{
            //    Name = "NameInsert",
            //    Age = 20 + 16,
            //    DTCreate = DateTime.Now
            //};
            //db.Insert(user1);

            //var user1 = new UserInfo() { Id = 1, Name = "Name1", HasDelete = true };
            //var snap = Snapshotter.Track(db, user1);

            //Snapshotter.SetGlobalIgnoreUpdatedColumns("Role", "DTCReaTE");
            var id    = 1;
            var user1 = db.Get <UserInfo>(id);
            var snap  = db.Track <UserInfo>(user1);

            var user = new UserInfo();

            user.Id   = 1;
            user.Name = Guid.NewGuid().ToString();
            // user.Sex = 1;
            //user.HasDelete = 1;
            user.DTCreate   = new DateTime(2002, 1, 1);
            user.Age        = 21;
            user.Role       = RoleType.经理;
            user.StatusCode = 0;

            //user1.CopyPropertiesFrom(user, "DTCReate");

            IDictionary <string, object> condition1 = new Dictionary <string, object>();

            condition1.Add("Name", "dfsd");
            condition1.Add("Id", 5);

            //
            var count2 = snap.UpdateWithIgnoreParams(user, null, po => po.Age, po => po.Email);
            var count  = snap.Update(user, null, "");

            Console.WriteLine(snap.Changes().Count);
            Console.WriteLine("UpdatedColumns:");
            foreach (var item in snap.UpdatedColumns())
            {
                Console.WriteLine(item);
            }
        }
Beispiel #13
0
        public static void Page()
        {
            var db = DbMocker.NewDataBase();

            UserInfo user = new UserInfo();

            user.Age  = 2;
            user.Id   = 1;
            user.Name = "sdf";
            var existss2 = db.Exists <UserInfo>(f => f.Age == RoleType.管理员.GetHashCode());
            var existss  = db.Exists <UserInfo>(f => f.Age > user.Age && f.Name == user.Name && f.Id != user.Id);

            string sql        = "select * from TB_USER2 where Age > 10 AND AGE > :P0";
            int    totalCount = 0;

            Dictionary <string, object> ps = new Dictionary <string, object>();

            ps.Add("P0", 34);

            var reader = db.ExecuteReader(sql, ps);
            //var expando = reader.ToExpandoObjects();
            var data = db.GetPageBySQL <UserInfo>(1, 10, sql, " Age ASC ", ps, out totalCount);

            int total = 0;

            var predicateGroup = new PredicateGroup {
                Operator = GroupOperator.And, Predicates = new List <IPredicate>()
            };

            predicateGroup.Predicates.Add(Predicates.Field <UserInfo>(f => f.Age, Operator.Gt, 10));
            predicateGroup.Predicates.Add(Predicates.Field <UserInfo>(f => f.Name, Operator.Eq, null, true));
            predicateGroup.Predicates.Add(Predicates.Field <UserInfo>(f => f.Name, Operator.Like, "NameInse%"));
            predicateGroup.Predicates.Add(Predicates.Field <UserInfo>(f => f.DTCreate, Operator.Ge, new DateTime(1982, 5, 8)));
            predicateGroup.Predicates.Add(Predicates.Field <UserInfo>(f => f.DTCreate, Operator.Le, DateTime.Now));

            IList <ISort> sortGroup = new List <ISort>();
            var           Sort      = Predicates.Sort <UserInfo>(f => f.DTCreate, false);

            sortGroup.Add(Sort);


            var listExt = db.GetPage <UserInfo>(0, 5, predicateGroup, sortGroup, out total);
            //db = DbMocker.NewDataBase(DatabaseType.SQLite);
            //listExt = db.GetPage<UserInfo>(1, 5, predicateGroup, sortGroup, out total);

            var list = db.GetPageByWhere <UserInfo>(0, 5, "Age > 10", "", out total);

            PrintHelper.WriteLine(total + "=" + list.Count());
        }
Beispiel #14
0
        public static void NestedTransactionThatFailsAbortsWholeUsingBeginAbort()
        {
            var db = DbMocker.NewDataBase();

            db.BeginTransaction();
            db.BeginTransaction();


            var user1 = new UserInfo
            {
                Name     = "Name" + 16,
                Age      = 20 + 16,
                DTCreate = new DateTime(1985, 1, 1)
            };

            db.Insert(user1);


            var extra1 = new UserInfo
            {
                Id    = user1.Id,
                Email = "email" + 16 + "@email.com",
                Name  = "Name" + 17
            };

            db.Insert(extra1);


            db.RollbackTransaction();

            var user3 = new UserInfo
            {
                Name     = "Name" + 16,
                Age      = 20 + 16,
                DTCreate = new DateTime(1970, 1, 1).AddYears(16)
            };

            db.Insert(user3);



            db.CommitTransaction();

            var count = db.ExecuteScalar <long>("SELECT COUNT(*) FROM TB_USER");
        }
Beispiel #15
0
        public static void NestedTransactionsBothCompleteUsingBeginAbort()
        {
            var db = DbMocker.NewDataBase();

            db.BeginTransaction();

            var user = new UserInfo
            {
                Name     = "Name" + 16,
                Age      = 20 + 16,
                DTCreate = new DateTime(1970, 1, 1).AddYears(16)
            };

            db.Insert(user);

            db.BeginTransaction();

            var user1 = new UserInfo
            {
                Name     = "Name" + 16,
                Age      = 20 + 16,
                DTCreate = new DateTime(1970, 1, 1).AddYears(16)
            };

            db.Insert(user1);

            var extra1 = new UserInfo
            {
                Name     = "Name" + 16,
                Age      = 20 + 16,
                DTCreate = new DateTime(1970, 1, 1).AddYears(16)
            };

            db.Insert(extra1);


            db.CommitTransaction();

            db.CommitTransaction();

            PrintHelper.WriteLine("Finish");
        }
Beispiel #16
0
        public static void InsertExecute()
        {
            var db = DbMocker.NewDataBase();

            IDictionary <string, object> pars           = new Dictionary <string, object>();
            IDictionary <string, object> RealParameters = new Dictionary <string, object>();

            //pars.Add("Id", 2);
            pars.Add("Name", "dd3");
            pars.Add("Sex", null);
            pars.Add("DTCreate", DateTime.Now);

            IDictionary <string, object> conditions = new Dictionary <string, object>();

            conditions.Add("Id", 2);
            conditions.Add("Name", "552");
            conditions.Add("Sex", true);

            int exeCount = db.Insert("TB_USER", pars);

            exeCount = db.Update("TB_USER", pars, conditions);

            exeCount = db.Delete("TB_USER", conditions);

            string[] selectCols = { "Id", "Name as dd" };
            var      sorts      = Predicates.SortGroup();

            sorts.Add(Predicates.Sort("DTCreate", true));
            sorts.Add(Predicates.Sort("Id", false));
            // var data = db.Query("TB_USER", selectCols, conditions, sorts).ToDictionary<string, object>();


            exeCount = db.Count("TB_USER", conditions);


            Console.WriteLine(exeCount);

            foreach (var item in RealParameters)
            {
                Console.WriteLine(item.Key + "=" + item.Value);
            }
        }
Beispiel #17
0
        public static void Insert()
        {
            var db = DbMocker.NewDataBase();

            IDictionary <string, object> pars           = new Dictionary <string, object>();
            IDictionary <string, object> RealParameters = new Dictionary <string, object>();

            pars.Add("Id", 2);
            pars.Add("Name", "dd3");
            pars.Add("Sex", null);
            pars.Add("DTCreate", DateTime.Now);

            IDictionary <string, object> conditions = new Dictionary <string, object>();

            conditions.Add("Id", 2);
            conditions.Add("Name", "552");
            conditions.Add("Sex", true);

            string sql = db.SqlGenerator.SqlCustomGenerator.Insert("TB_USER", pars, out RealParameters);

            //  sql = db.SqlGenerator.SqlCustomGenerator.Update("TB_USER", pars,conditions, out RealParameters);

            //  sql = db.SqlGenerator.SqlCustomGenerator.Delete("TB_USER", conditions, out RealParameters);

            string[] selectCols = { "Id", "Name as dd" };
            var      sorts      = Predicates.SortGroup();

            sorts.Add(Predicates.Sort("DTCreate", true));
            sorts.Add(Predicates.Sort("Id", false));
            sql = db.SqlGenerator.SqlCustomGenerator.Select("TB_USER", selectCols, conditions, sorts, out RealParameters);


            sql = db.SqlGenerator.SqlCustomGenerator.Count("TB_USER", conditions, out RealParameters);


            Console.WriteLine(sql);

            foreach (var item in RealParameters)
            {
                Console.WriteLine(item.Key + "=" + item.Value);
            }
        }
Beispiel #18
0
        public static void Test()
        {
            string title = "CRUDTest";

            Console.Title = title;
            var db = DbMocker.InstanceDataBase();

            //db.Config.EnableOrmLog = false;
            //db.Config.EnableDebug = true;
            //db.Config.Interceptors.Add(new ConnectionTestIntercept());
            PrintHelper.WriteLine("Add ConnectionTestIntercept");
            db.LogHelper.Write("Add ConnectionTestIntercept");
            CodeTimer.Time(title, 100, () => {
                //Insert();
                Update(db);
            });


            Console.Read();
        }
Beispiel #19
0
        public static void Test()
        {
            string title = "ClassMapTest";

            Console.Title = title;
            var db = DbMocker.InstanceDataBase();

            db.Config.EnableDebug     = false;
            db.Config.EnableOrmCache  = false;
            db.Config.EnableOrmLog    = false;
            db.Config.EnableIntercept = false;

            CodeTimer.Time(title, 1, () => {
                GetAttributeMap(db);
                //LoadAll(db);
            });


            Console.Read();
        }
Beispiel #20
0
        public static void Gen()
        {
            var db = DbMocker.NewDataBase();

            db.GenerateCode();

            // var option = new CodeGenOption();
            // option.Enable = true;
            // option.OutputDir = PathHelper.CombineWithBaseDirectory("puredata_gen");
            // option.FilterTablePrefixs = "TB_;B_";
            // option.Namespace = "Pure.Test.Domain";
            //// option.IncludeTableNames = "tb_user;";
            // option.ClassNameMode = ClassNameMode.UpperOrigin;
            // option.PropertyNameMode = ClassNameMode.UpperOrigin;

            // var result = CodeGenHelper.Instance.Gen(db, DbMigrateService.Instance, option);


            // Console.WriteLine(result.ToString());
        }
Beispiel #21
0
        static void PureDataQueryTest3(int takeCount, int id)
        {
            using (var db = DbMocker.NewDataBase())
            {
                //single
                //var db = DbMocker.InstanceDataBase();
                //single but new connection
                //var db = DbMocker.InstanceDataBase().CreateNewConnection();
                db.Config.EnableOrmLog    = false;
                db.Config.EnableDebug     = false;
                db.Config.EnableIntercept = false;
                //db.DatabaseConfig.EnableDebug = true;
                //db.DatabaseConfig.Interceptors.Add(new ConnectionTestIntercept());

                // var list = db.Query<UserInfo>(p => p.Id > id, (p) => { p.Top(takeCount); }).ToList(); // string.Format("select top {0} * from TB_USER where Id>@Id", takeCount.ToString(), new { Id = id })).ToList();
                var predict = Predicates.Field <UserInfo>(f => f.Id, Operator.Gt, id, false);
                var list    = db.Query <UserInfo>(predict).ToList();
                //PrintHelper.WriteLine(list.Count.ToString());
            }
        }
Beispiel #22
0
        public static void Test()
        {
            string title = "TransactionTest";

            Console.Title = title;

            CodeTimer.Time(title, 1, () => {
                using (var db = DbMocker.NewDataBase())
                {
                    var count = db.ExecuteScalar <long>("SELECT COUNT(*) FROM TB_USER");

                    PrintHelper.WriteLine("count=" + count);
                }

                //NestedTransactionThatFailsAbortsWholeUsingBeginAbort();
                //NestedTransactionsBothCompleteUsingBeginAbort();
            });


            Console.Read();
        }
Beispiel #23
0
        public static void Convert()
        {
            var db = DbMocker.NewDataBase();

            Expression2SqlTest.UserInfoMapper mapper = new Expression2SqlTest.UserInfoMapper();
            UserInfo v = new UserInfo();

            v.Name  = "http://www.sdfd.com";
            v.Age   = 1;
            v.Email = "*****@*****.**";
            v.Name  = "<script>alert(3242)</script>";

            var result = mapper.Validate(db, v, "Age");


            var result2 = db.Validate(v, m => m.Name, m => m.Age);
            var result3 = mapper.Validate(db, v);

            Console.WriteLine(result.ToString());
            Console.WriteLine(result2.ToString());
            Console.WriteLine(result3.ToString());
        }
Beispiel #24
0
        public static void Update()
        {
            var db = DbMocker.NewDataBase();


            var user1 = new UserInfo
            {
                Name     = "NameTest" + 16,
                Age      = 20 + 16,
                DTCreate = new DateTime(1985, 1, 1)
            };
            int id = 5;
            var dd = db.Get <UserInfo>(id);

            dd.Name = "5345435";
            var co = db.Update <UserInfo>(dd);

            db.Update <UserInfo>(() => new UserInfo {
                Age = 88, Name = "李玮峰"
            }, p => p.Id == 5);
            // db.Update<UserInfo>(() => {return user1;}, p => p.Id == 5);
        }
Beispiel #25
0
        public static void Query()
        {
            var db    = DbMocker.NewDataBase();
            int total = 0;


            string   name    = null;
            UserInfo predict = new UserInfo();

            predict.Id       = 2;
            predict.Name     = "lee";
            predict.DTCreate = DateTime.Now;

            //string[] names = null;

            var names = new List <string>()
            {
                "23", "44"
            };

            var one = db.Get <UserInfo>(5);

            var o = db.ExecuteDictionary <string, int>("SELECT T.NAME, SUM(T.Id) FROM TB_USER T GROUP BY T.NAME");

            db = DbMocker.NewDataBase();
            db.Delete <UserInfo>(p => names.Contains(p.Name));
            string name1 = "gsfdgdf";
            var    list2 = db.Query <UserInfo>(p => p.Name == name1 && SqlFuncs.In(p.Name, names));

            db = DbMocker.NewDataBase();
            var list3 = db.Query <UserInfo>(p => p.Name == name1 && names.Contains(p.Name));


            //var list = db.Query<UserInfo>(p => predict.Id < p.Id).ToList();
            //var list1 = db.Query<UserInfo>(p =>p.Id > predict.Id &&  p.Name.Contains(predict.Name)  && p.DTCreate  > predict.DTCreate || p.Id  > 0).ToList();
            //var list2 = db.Query<UserInfo>(p => predict.DTCreate<p.DTCreate).ToList();

            PrintHelper.WriteLine("");
        }
        public static void Test()
        {
            string title = "FluentExpressionSqlBuilderTest";

            Console.Title = title;
            var db = DbMocker.InstanceDataBase();

            //db.Config.EnableOrmLog = false;
            //db.Config.EnableDebug = true;
            //db.Config.Interceptors.Add(new ConnectionTestIntercept());

            //db.LogHelper.Write("Add ConnectionTestIntercept");
            CodeTimer.Time(title, 1, () => {
                //CreateSql(db);
                //Update(db);
                //FetchWhereExpression(db);
                Query(db);
            });


            Console.Read();
        }
Beispiel #27
0
 public static void Migrate2()
 {
     var db = DbMocker.InstanceDataBase();
 }
Beispiel #28
0
        public static async Task SqlMapMethodTest()
        {
            var db = DbMocker.NewDataBase();

            try
            {
                List <UserInfo> dd = new List <UserInfo>();
                dd.Add(new UserInfo()
                {
                    Name = "fdd", Id = 32
                });



                dd.Add(new UserInfo()
                {
                    Name = "范德萨", Id = 22
                });

                db = DbMocker.NewDataBase();
                var user = new UserInfo()
                {
                    Id = 9, Name = "'eo\"莱卡布\""
                };

                var resultGetListLinqTest = db.QuerySqlMap("TB_USER", "GetListLinqTest", new { Name = "fsdsd", ID = 2, Nam = "23", LikeNames = dd, Ids = new long[] { 1, 2, 3, 4 } });
                db.LogHelper.Write(resultGetListLinqTest.RawSql);


                var result6 = db.QuerySqlMap("TB_USER", "GetListInclude", new { Name = "fsdsd", ID = 2, Nam = "23", Ids = new long[] { 1, 2, 3, 4 } });
                db.LogHelper.Write(result6.RawSql);

                var resultGetListForeachIncludeIfTest = db.QuerySqlMap("TB_USER", "GetListForeachIncludeIfTest", new { Name = "fsdsd", ID = 2, Nam = "23", LikeNames = dd, Ids = new long[] { 1, 2, 3, 4 } });
                var dataGetListForeachIncludeIfTest   = resultGetListForeachIncludeIfTest.ExecuteList <object>();

                var resultGetListChooseTest = db.QuerySqlMap("TB_USER", "GetListChooseTest", new { Name = "fsdsd", ID = 2, Nam = "23", Ids = new long[] { 1, 2, 3, 4 } });
                var dataGetListChooseTest   = resultGetListChooseTest.ExecuteList <object>();



                var resultupdateUserSetTest = db.QuerySqlMap("TB_USER", "updateUserSetTest", new { Name = "fsdsd", ID = 2, Nam = "23", Ids = new long[] { 1, 2, 3, 4 } });
                var dataupdateUserSetTest   = resultupdateUserSetTest.ExecuteList <object>();



                var resultGetListTrimTest = db.QuerySqlMap("TB_USER", "GetListTrimTest", new { Name = "fsdsd", ID = 2, Nam = "23", Ids = new long[] { 1, 2, 3, 4 } });
                var dataGetListTrimTest   = resultGetListTrimTest.ExecuteList <object>();


                var resultGetListBindTest = db.QuerySqlMap("TB_USER", "GetListBindTest", new { Name = "fsdsd", ID = 2, Nam = "23", Ids = new long[] { 1, 2, 3, 4 } });
                var dataGetListBindTest   = resultGetListBindTest.ExecuteList <object>();

                var result55 = db.QuerySqlMap("TB_USER", "GetListIfTest", new { Name = "fsdsd", ID = 2, Nam = "23", Ids = new long[] { 1, 2, 3, 4 } });
                db.LogHelper.Write(result55.Sql);
                var data55 = result55.ExecuteList <object>();



                //var result88 = await db.UpdateOnlyAsync<UserInfo>(user,null, "Name", "Age");



                //var result5 = db.QuerySqlMap("TB_USER", "GetListTest", new { Name="fsdsd", ID = 2, Nam="23", Ids = new long[] { 1, 2, 3, 4 } });
                //db.LogHelper.Write(result5.Sql);



                //db.LogHelper.Write("------------rawsql: " + result5.RawSql);
                //var data5 = result5.ExecuteList<object>();

                //List<UserInfo> dd = new List<UserInfo>();
                //dd.Add(new UserInfo() { Name = "fdd", Id = 32 });



                //dd.Add(new UserInfo() { Name = "范德萨", Id = 22 });
                // dd = null;
                //var result2 = db.QuerySqlMap("TB_USER", "GetListByFor", new { Id = 9, Name = "eo", OrderBy = 3, Yes = true, No = true, LikeNames = dd });
                //db.LogHelper.Write(result2.Sql);
                //db.LogHelper.Write("------------rawsql: " + result2.RawSql);

                //var data2 = result2.ExecuteList<UserInfo>();


                //var TestVari = db.QuerySqlMap("TB_USER", "TestVari", new { tablename = "tablename2", ordertext = "name", orderdesc = "desc", Yes = true, Name = "" });
                //db.LogHelper.Write(TestVari.Sql);
                //db.LogHelper.Write("------------rawsql: " + TestVari.RawSql);

                //int total = 0;
                //var result44 = db.QuerySqlMap("TB_USER", "GetList", new { tablename = "刚发的", Id = 9, Name = "'eo\"莱卡布\"", Ids = new long[] { 1, 2, 3, 4 } });
                //var data44 = result44.ExecutePageList<UserInfo>(1, 10, out total, "");



                ////获取列表In
                //var result = db.QuerySqlMap("TB_USER", "GetList", new { Ids = new long[] { 1, 2, 3, 4 } });
                //db.LogHelper.Write(result.Sql);
                //db.LogHelper.Write("------------rawsql: "+result.RawSql);

                //var data = result.ExecuteList<UserInfo>();


                ////组合查询
                //var result1 = db.QuerySqlMap("TB_USER", "GetListCombine", new { Id = 9, Name = "'eo\"莱卡布\"" });
                //db.LogHelper.Write(result1.Sql);
                //db.LogHelper.Write("------------rawsql: " + result1.RawSql);

                //var data1 = result1.ExecuteList<UserInfo>();
                //db = DbMocker.NewDataBase();

                //var result2 = db.QuerySqlMap("TB_USER", "GetListInclude", new { Id = 9, Name = "eo", OrderBy = 3, Yes = true, No = true, LikeNames = new string[] { "2", "55" } });
                //db.LogHelper.Write(result2.Sql);
                //db.LogHelper.Write("------------rawsql: " + result2.RawSql);

                //var data2 = result2.ExecuteList<UserInfo>();

                // System.Threading.Thread.Sleep(2 * 1000);
            }
            catch (Exception ex)
            {
                db.LogHelper.Error(ex);

                throw;
            }
            finally
            {
                db.Close();
            }
        }
Beispiel #29
0
 public static void Constuct()
 {
     using (var db = DbMocker.NewDataBase())
     {
     }
 }
Beispiel #30
0
 public static void CreateDataBase()
 {
     using (var db = DbMocker.NewDataBase())
     {
     }
 }