How to choose what fields not to Update in EF
When updating an Entity in EF that have a CreatedDate or any other property that you don't want to update, you have two options, either store and keep the original value or you can tell EF that some properties haven't been modified, even if they have been.
var myEntry = context.Entry(entity);
myEntry .State = EntityState.Modified;
foreach (var name in excludedProperties)
{
entry.Property(name).IsModified = false;
}
Where excludedProperties is a list of strings containing all the properties to exclude, and entity the entity to be modified.
Written by Luis Tellez
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#C#
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#