- 积分
- 33
- 在线时间
- 87 小时
- 主题
- 2
- 注册时间
- 2013-6-29
- 帖子
- 31
- 最后登录
- 2023-6-21
- 帖子
- 31
- 软币
- 918
- 在线时间
- 87 小时
- 注册时间
- 2013-6-29
|
本帖最后由 jinlshan 于 2013-10-7 17:54 编辑
第一次使用EF,在更新数据时,如果只更新其中部分字段,为什么生成的Update SQL语句会是把所有的字段都更新了呢?代码如下:(我使用的是DbContext,而且Opr_Pro_Work不是继承自EntityObject类)
using (JLSContext db = JLSDBContextManager.GenerateJLSContext())
{
Opr_Pro_Work w1=db.Opr_Pro_Work.Where(it=>it.WorkID==1).FirstOrDefault(); w1.IsPrint = true;
db.Entry(w1).State = EntityState.Modified;
db.SaveChanges();
}
生成的SQL语句:
exec sp_executesql N'update [dbo].[Opr_Pro_Work]
set [WorkNo] = @0, [BarCode] = @1, [PID] = @2, [StoOutID] = @3, [StoOutNo] = @4, [OrderID] = @5, [OrderDID] = @6, [CaseID] = @7, [CaseNo] = @8, [ProNO] = @9, [ColorName] = @10, [SizeName] = @11, [UnitName] = @12, [IndexID] = @13, [PNo] = @14, [PName] = @15, [FctCntWage] = @16, [Qty] = @17, [Wages] = @18, [EmpID] = @19, [EmpName] = null, [InstID] = null, [InstName] = null, [WageID] = @20, [WorkDate] = null, [WorkDatetime] = null, [WorkMan] = null, [InputDate] = @21, [InputDatetime] = @22, [InputMan] = @23, [Printed] = @24, [Inserted] = @25, [ByHand] = @26, [PrintGroupID] = @27, [IsPrint] = @28, [Status] = @29
where ([WorkID] = @30)
',N'@0 nvarchar(20),@1 nvarchar(30),@2 int,@3 int,@4 nvarchar(20),@5 int,@6 int,@7 int,@8 nvarchar(50),@9 nvarchar(50),@10 nvarchar(110),@11 nvarchar(100),@12 nvarchar(100),@13 int,@14 nvarchar(6),@15 nvarchar(50),@16 decimal(30,12),@17 decimal(30,12),@18 decimal(30,12),@19 nvarchar(6),@20 int,@21 datetime2(7),@22 datetime2(7),@23 nvarchar(50),@24 bit,@25 bit,@26 int,@27 int,@28 bit,@29 int,@30 bigint',@0=N'00000000000000000198',@1=N'OP20130900000645610576045',@2=87,@3=17,@4=N'OP201309000006',@5=109,@6=181,@7=36,@8=N'456',@9=N'0',@10=N'白色 11-0601',@11=N'34/36',@12=N'件',@13=45,@14=N'10576',@15=N'反送活',@16=18000000000,@17=30.000000000000,@18=0.540000000000,@19=N'',@20=0,@21='2013-10-05 00:00:00',@22='2013-10-05 10:46:44.3300000',@23=N'Admin',@24=1,@25=0,@26=0,@27=1,@28=1,@29=0,@30=198
|
|