所以我认为答案是:
modelBuilder.Entity<MyObject>(builder =>
{
builder.Property(e => e.Prop7).Metadata.AfterSaveBehavior = PropertySaveBehavior.Ignore;
builder.Property(e => e.Prop8).Metadata.AfterSaveBehavior = PropertySaveBehavior.Ignore;
builder.Property(e => e.Prop9).Metadata.AfterSaveBehavior = PropertySaveBehavior.Ignore;
});
但是我该如何动态地做到这一点?如何在需要时阻止EF core更新,并允许它在大多数情况下像往常一样更新。
答案 0 :(得分:0)
您可以将PropertyEntry.IsModified
设置为false
,这将重置属性的值。
var myObject = ctx.MyObjects.First(); // e.g. myObject.Foo is "foo" in the database
myObject.Foo = "bar";
ctx.Entry(myObject).Property(o => o.Foo).IsModified = false;
// at this point, myObject.Foo is reset to "foo"