I recently started using Entity Framework, and it has been kind of a pain to check if I really need to add new records to the database or not.
If the Entity I n
I know that I am a little late to this post, but was looking for similar solution... and then I found this Microsoft article which may succinctly answers most of the OP's questions, and may help future SO viewers?:
Add/Attach and Entity States == ( http://msdn.microsoft.com/en-us/data/jj592676.aspx )
From the article:
This topic will cover how to add and attach entities to a context and how Entity Framework processes these during SaveChanges.
And specifically see the last section on that page:
Insert or update pattern: A common pattern for some applications is to either Add an entity as new (resulting in a database insert) or Attach an entity as existing and mark it as modified (resulting in a database update) depending on the value of the primary key.