from:
http://stackoverflow.com/questions/7552433/what-is-the-equivalent-for-hibenate-saveorupdate-in-entity-framework
果然是stackflow,馬上找到
There is no equivalent. You really have to write it like:
using (DataContext context = new DataContext()) { context.Task.Attach(task); if (task.ID == 0) { context.ObjectStateManager.ChangeObjectState(task, System.Data.EntityState.Added); } else { context.ObjectStateManager.ChangeObjectState(task, System.Data.EntityState.Modified); } context.SaveChanges(); }