我刚刚向我的某个实体添加了更多属性,现在我无法更新它们。
以下是我的代码片段:
Artikal art = db.Artikli.First();
art.Image = picbyte;
art.BarcodeType = "UAC";
art.Model = "RayBan";
art.StrProperty1 = "aaaa";
art.StrProperty2 = "bbbb";
art.StrProperty5 = "cccc";
db.SaveChanges();
Image
,Model
和StrProperty5
是新添加的字段,其余字段为“旧”字段。
这是我通过探查器捕获的内容:
exec sp_executesql N'update [dbo].[Artikli]
set [StrProperty1] = @0, [StrProperty2] = @1, [BarcodeType] = @2
where ([IdArtikal] = @3)
',N'@0 nvarchar(256),@1 nvarchar(256),@2 nvarchar(16),@3 int',@0=N'aaaa',@1=N'bbbb',@2=N'UAC',@3=1
因此,EF甚至不会尝试更新这些“新”属性。
我刚刚添加了属性,模型优先,从模型更新数据库,就像我以前做过很多次一样。
可能出了什么问题?我该如何解决这个问题?