LINK - https://msdn.microsoft.com/en-us/data/jj592676.aspx
public void InsertOrUpdate(Blog blog)
{
using (var context = new BloggingContext())
{
context.Entry(blog).State = blog.BlogId == 0 ?
EntityState.Added :
EntityState.Modified;
context.SaveChanges();
}
}
LINK - EF6 Update/Insert model object from outside of context
原文:http://blog.csdn.net/jameszhou/article/details/50010105