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

沒有留言:

windows 無法拖動文件

原因:未知 症狀:windows點任何文件,都無法拖動到其他地方  解決方式: 來源: https://answers.microsoft.com/en-us/windows/forum/all/drag-and-drop-stopped-working/b73e4938-ca2...