Entity Framework ignore objects Insert/Update on SaveChanges()

Assume you have an object:

var myItem = new MyItem()
  Name = "Alex"

If you want to ignore this object when calling SaveChanges() to do UPDATE or INSERT into database just use this command:

Db.Entry(myItem).State = EntityState.Detached;

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.