Ejemplo n.º 1
0
        public static void Updateable()
        {
            Db.CodeFirst.InitTables(typeof(UnitUser));
            Db.DbMaintenance.TruncateTable <UnitUser>();
            Db.Insertable(new UnitUser()
            {
                USER_ID = 1, USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now
            }).ExecuteCommand();
            Db.Updateable(new UnitUser()
            {
                USER_ID = 1, PWD_LASTERRTIME = null
            }).WhereColumns(it => new{ it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
            Db.CodeFirst.InitTables(typeof(UnitBoolTest));
            var x = new UnitBoolTest();

            //Db.Updateable<UnitBoolTest>().SetColumns(it => new UnitBoolTest() { BoolValue = !it.BoolValue }).Where(it=>it.Id==1).ExecuteCommand();
            //Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == !it.BoolValue  ).Where(it=>it.Id==1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            //Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == !x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue == it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue == true).ExecuteCommand();
            //Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == !it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).UpdateColumns(it => new { it.BoolValue }).ExecuteCommand();



            UnitSaveDiary saveDiary = new UnitSaveDiary();

            saveDiary.ID       = 2;
            saveDiary.TypeID   = 10;
            saveDiary.TypeName = "类型100";
            saveDiary.Title    = "标题1000";
            saveDiary.Content  = "内容";
            saveDiary.Time     = DateTime.Now;
            saveDiary.IsRemind = false;//无论传false/true 最终执行的结果都是以true执行的

            var sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                IsRemind = saveDiary.IsRemind,
            }).Where(it => it.ID == saveDiary.ID).ToSql();

            UValidate.Check(sql.Key, @"UPDATE ""diary""  SET
            ""isremind"" =  @Const0    WHERE ( ""id"" = @ID1 )", "Updateable");


            sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                TypeID = saveDiary.TypeID,
            }).Where(it => it.ID == saveDiary.ID).ToSql();
            UValidate.Check(sql.Key, @"UPDATE ""diary""  SET
            ""typeid"" = @Const0   WHERE ( ""id"" = @ID1 )", "Updateable");
        }
Ejemplo n.º 2
0
        public static void Updateable()
        {
            Db.CodeFirst.InitTables(typeof(UnitUser));
            Db.DbMaintenance.TruncateTable <UnitUser>();
            Db.Insertable(new UnitUser()
            {
                USER_ID = 1, USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now
            }).ExecuteCommand();
            Db.Updateable(new UnitUser()
            {
                USER_ID = 1, PWD_LASTERRTIME = null
            }).WhereColumns(it => new{ it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
            Db.CodeFirst.InitTables(typeof(UnitBoolTest));
            var x = new UnitBoolTest();

            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !it.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == !it.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == !x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue == it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue == true).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue == !it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).UpdateColumns(it => new { it.BoolValue }).ExecuteCommand();



            UnitSaveDiary saveDiary = new UnitSaveDiary();

            saveDiary.ID       = 2;
            saveDiary.TypeID   = 10;
            saveDiary.TypeName = "类型100";
            saveDiary.Title    = "标题1000";
            saveDiary.Content  = "内容";
            saveDiary.Time     = DateTime.Now;
            saveDiary.IsRemind = false;//无论传false/true 最终执行的结果都是以true执行的

            var sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                IsRemind = saveDiary.IsRemind,
            }).Where(it => it.ID == saveDiary.ID).ToSql();

            UValidate.Check(sql.Key, @"UPDATE `Diary`  SET
            `IsRemind` =  @Const0    WHERE ( `ID` = @ID1 )", "Updateable");


            sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                TypeID = saveDiary.TypeID,
            }).Where(it => it.ID == saveDiary.ID).ToSql();
            UValidate.Check(sql.Key, @"UPDATE `Diary`  SET
            `TypeID` = @Const0   WHERE ( `ID` = @ID1 )", "Updateable");

            Db.CodeFirst.InitTables <UnitDSsdfa>();
            var dt = DateTime.Now;

            Db.Insertable(new UnitDSsdfa()
            {
                pk = dt, value = 1
            }).ExecuteCommand();
            var list = new List <UnitDSsdfa>()
            {
                new UnitDSsdfa()
                {
                    pk = dt, value = 2
                }
            };

            for (int i = 0; i < 100; i++)
            {
                list.Add(new UnitDSsdfa()
                {
                    pk = dt, value = 2
                });
            }
            var res1 = Db.Updateable(list).WhereColumns(it => it.pk).ExecuteCommand();
        }
Ejemplo n.º 3
0
        public static void Updateable()
        {
            Db.CodeFirst.InitTables(typeof(UnitUser));
            Db.DbMaintenance.TruncateTable <UnitUser>();
            Db.Insertable(new UnitUser()
            {
                USER_ID = 1, USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now
            }).ExecuteCommand();
            Db.Updateable(new UnitUser()
            {
                USER_ID = 1, PWD_LASTERRTIME = null
            }).WhereColumns(it => new{ it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
            Db.CodeFirst.InitTables(typeof(UnitBoolTest));
            var x = new UnitBoolTest();

            //Db.Updateable<UnitBoolTest>().SetColumns(it => new UnitBoolTest() { BoolValue = !it.BoolValue }).Where(it=>it.Id==1).ExecuteCommand();
            //Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == !it.BoolValue  ).Where(it=>it.Id==1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            //Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == !x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue == it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue == true).ExecuteCommand();
            //Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == !it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).UpdateColumns(it => new { it.BoolValue }).ExecuteCommand();



            UnitSaveDiary saveDiary = new UnitSaveDiary();

            saveDiary.ID       = 2;
            saveDiary.TypeID   = 10;
            saveDiary.TypeName = "类型100";
            saveDiary.Title    = "标题1000";
            saveDiary.Content  = "内容";
            saveDiary.Time     = DateTime.Now;
            saveDiary.IsRemind = false;//无论传false/true 最终执行的结果都是以true执行的

            var sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                IsRemind = saveDiary.IsRemind,
            }).Where(it => it.ID == saveDiary.ID).ToSql();

            UValidate.Check(sql.Key, @"UPDATE ""diary""  SET
            ""isremind"" =  @Const0    WHERE ( ""id"" = @ID1 )", "Updateable");


            sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                TypeID = saveDiary.TypeID,
            }).Where(it => it.ID == saveDiary.ID).ToSql();
            UValidate.Check(sql.Key, @"UPDATE ""diary""  SET
            ""typeid"" = @Const0   WHERE ( ""id"" = @ID1 )", "Updateable");

            Db.Updateable <OrderModel>().SetColumns(it => new OrderModel()
            {
                CreateTime = null
            }).Where(it => it.Id == 1).ExecuteCommand();

            Db.CodeFirst.InitTables <BoolTest1>();
            Db.Updateable <BoolTest1>()
            .SetColumns(it => it.a == !it.a)
            .Where(it => it.a)
            .ExecuteCommand();

            Db.Updateable <BoolTest1>()
            .SetColumns(it => new BoolTest1()
            {
                a = !it.a
            })
            .Where(it => it.a)
            .ExecuteCommand();

            // Db.CodeFirst.InitTables<UnitPk00121>();
            //Db.CodeFirst.InitTables<UnitPk001212>();
            //Db.Deleteable<UnitPk00121>().Where(new UnitPk00121() { Id=1, CreateTime=DateTime.Now, Name="a" }).ExecuteCommand();
            //Db.Deleteable<UnitPk001212>().Where(new List<UnitPk001212> { new UnitPk001212() { Id = 1, CreateTime = DateTime.Now, Name = "a" } , new UnitPk001212() { Id = 2, CreateTime = DateTime.Now, Name = "11a" } }).ExecuteCommand();
            Db.CodeFirst.InitTables <UnitDSsdfa>();
            var dt = DateTime.Now;

            Db.Insertable(new UnitDSsdfa()
            {
                pk = dt, value = 1
            }).ExecuteCommand();
            var list = new List <UnitDSsdfa>()
            {
                new UnitDSsdfa()
                {
                    pk = Convert.ToDateTime("2022-1-1"), value = 2
                }, new UnitDSsdfa()
                {
                    pk = dt, value = 2
                }
            };
            var res1 = Db.Updateable(list).WhereColumns(it => it.pk).ExecuteCommand();
        }
Ejemplo n.º 4
0
        public static void Updateable()
        {
            Db.CodeFirst.InitTables(typeof(UnitUser));
            Db.DbMaintenance.TruncateTable <UnitUser>();
            Db.Insertable(new UnitUser()
            {
                USER_ID = 1, USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now
            }).ExecuteCommand();
            Db.Updateable(new UnitUser()
            {
                USER_ID = 1, PWD_LASTERRTIME = null
            }).WhereColumns(it => new { it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
            Db.CodeFirst.InitTables(typeof(UnitBoolTest));
            var x = new UnitBoolTest();

            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !it.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == !it.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == !x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue = it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue = true).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue = !it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).UpdateColumns(it => new { it.BoolValue }).ExecuteCommand();



            UnitSaveDiary saveDiary = new UnitSaveDiary();

            saveDiary.ID       = 2;
            saveDiary.TypeID   = 10;
            saveDiary.TypeName = "类型100";
            saveDiary.Title    = "标题1000";
            saveDiary.Content  = "内容";
            saveDiary.Time     = DateTime.Now;
            saveDiary.IsRemind = false;//无论传false/true 最终执行的结果都是以true执行的

            var sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                IsRemind = saveDiary.IsRemind,
            }).Where(it => it.ID == saveDiary.ID).ToSql();

            UValidate.Check(sql.Key, @"UPDATE [Diary]  SET
            [IsRemind] =  @Const0    WHERE ( [ID] = @ID1 )", "Updateable");


            sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                TypeID = saveDiary.TypeID,
            }).Where(it => it.ID == saveDiary.ID).ToSql();
            UValidate.Check(sql.Key, @"UPDATE [Diary]  SET
            [TypeID] = @Const0   WHERE ( [ID] = @ID1 )", "Updateable");


            sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                TypeID = saveDiary.TypeID,
            }).Where(it => it.ID == saveDiary.ID).ToSql();
            UValidate.Check(sql.Key, @"UPDATE [Diary]  SET
            [TypeID] = @Const0   WHERE ( [ID] = @ID1 )", "Updateable");

            sql = Db.Updateable <NullTest>().SetColumns(it => new NullTest()
            {
                p = true
            }).Where(it => it.id == 1).ToSql();
            UValidate.Check(sql.Key, @"UPDATE [NullTest]  SET
            [p] =  @Const0    WHERE ( [id] = @id1 )", "Updateable");
            sql = Db.Updateable <NullTest>().SetColumns(it => new NullTest()
            {
                p2 = true
            }).Where(it => it.id == 1).ToSql();
            UValidate.Check(sql.Key, @"UPDATE [NullTest]  SET
            [p2] = @Const0   WHERE ( [id] = @id1 )", "Updateable");


            Db.Updateable <Order>()
            .SetColumns(it => it.Name == "a")
            .SetColumns(it => it.CreateTime == DateTime.Now)
            .SetColumns(it => it.Price == 1).Where(it => it.Id == 1).ExecuteCommand();


            Db.Updateable <Order>()
            .SetColumns(it => new Order {
                Name = "a", CreateTime = DateTime.Now
            })
            .SetColumns(it => it.Price == 1).Where(it => it.Id == 1).ExecuteCommand();



            Db.Updateable <Order>()
            .SetColumns(it => new Order {
                Name = "a", CreateTime = DateTime.Now
            })
            .SetColumns(it => new Order()
            {
                Price = 1
            }).Where(it => it.Id == 1).ExecuteCommand();

            Db.Updateable <Order>()
            .SetColumns(it => new Order {
                Name = it.Id > 0  ?"1":"2", CreateTime = DateTime.Now
            })
            .Where(it => it.Id == 1).ExecuteCommand();

            Db.Updateable <Order>()
            .SetColumns(it => new Order {
                Name = SqlFunc.IsNull(it.Name, "a") + "b", CreateTime = DateTime.Now
            })
            .Where(it => it.Id == 1).ExecuteCommand();

            Db.CodeFirst.InitTables <Unitbluecopy>();
            Db.Insertable(new Unitbluecopy()).UseSqlServer().ExecuteBulkCopy();
        }
Ejemplo n.º 5
0
        public static void Updateable()
        {
            Db.CodeFirst.InitTables(typeof(UnitUser));
            Db.DbMaintenance.TruncateTable <UnitUser>();
            Db.Insertable(new UnitUser()
            {
                USER_ID = 1, USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now
            }).ExecuteCommand();
            Db.Updateable(new UnitUser()
            {
                USER_ID = 1, PWD_LASTERRTIME = null
            }).WhereColumns(it => new{ it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
            Db.CodeFirst.InitTables(typeof(UnitBoolTest));
            var x = new UnitBoolTest();

            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !it.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == !it.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => new UnitBoolTest()
            {
                BoolValue = !x.BoolValue
            }).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>().SetColumns(it => it.BoolValue == !x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue = it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue = true).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).ReSetValue(it => it.BoolValue = !it.BoolValue).ExecuteCommand();
            Db.Updateable <UnitBoolTest>(x).UpdateColumns(it => new { it.BoolValue }).ExecuteCommand();



            UnitSaveDiary saveDiary = new UnitSaveDiary();

            saveDiary.ID       = 2;
            saveDiary.TypeID   = 10;
            saveDiary.TypeName = "类型100";
            saveDiary.Title    = "标题1000";
            saveDiary.Content  = "内容";
            saveDiary.Time     = DateTime.Now;
            saveDiary.IsRemind = false;//无论传false/true 最终执行的结果都是以true执行的

            var sql = Db.Updateable <UnitDiary>().SetColumns(it => new UnitDiary()
            {
                IsRemind = saveDiary.IsRemind,
            }).Where(it => it.ID == saveDiary.ID).ToSql();

            // UValidate.Check(sql.Key, @"UPDATE ""UNITBOOLTEST""  SET
            //""BOOLVALUE"" =:BoolValue  WHERE ""ID"" =:Id"", "Updateable");


            //  sql = Db.Updateable<UnitDiary>().SetColumns(it => new UnitDiary()
            //{
            //   TypeID = saveDiary.TypeID,
            //}).Where(it => it.ID == saveDiary.ID).ToSql();
            //UValidate.Check(sql.Key, @"UPDATE ""DIARY""  SET
            //""TYPEID"" = @Const0   WHERE ( ""ID"" = :ID1 )", "Updateable");
            Db.CodeFirst.InitTables <UnitGuidTest>();
            Db.Updateable(new List <UnitGuidTest> {
                new UnitGuidTest()
                {
                    Id = Guid.NewGuid(), name = "a", guid = Guid.NewGuid()
                },
                new UnitGuidTest()
                {
                    Id = Guid.NewGuid(), name = "a"
                }
            }).ExecuteCommand();

            var updateObjs = new List <Order> {
                new Order()
                {
                    Id = 11, Name = "order11"
                }
            };

            //update all columns by primary key

            if (Db.Updateable(updateObjs).ExecuteCommandAsync().GetAwaiter().GetResult() != 1)
            {
                throw new Exception("unit error");
            }
        }