2015/12/18

EF framework LIKE Hibernate SaveOrUpdate()


 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();
 }

沒有留言:

JPA+complex key+custom Query

  來源: https://www.cnblogs.com/520playboy/p/6512592.html   整個來說,就是有複合主鍵 然後要使用  public interface XxXXxx DAO extends CrudRepository<Tc...