1

So I've seen the answer to this as being:

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;
});

But how can I do this dynamically? How can I stop EF core from updating when I want it to, and allow it to update as usual the majority of the time.

1 Answer 1

0

You can set the PropertyEntry.IsModified to false which will reset the property's value.

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.