我想保存一个对象,然后从数据库中检索它,但不知何故,保存有效,但检索返回 null。
public static Work startWork(Work work)
{
Context.context.Work.AddObject(work);
Context.context.SaveChanges();
Work result = (from r in Context.context.Work
where r.ReceiptID == work.ReceiptID && r.begin == work.begin
select r).FirstOrDefault();
return result;
}
因此,我传递了一个已经设置了 begin
和 ReceiptID
的工作实例,以便我可以检索它,但它只是返回 null。
最佳答案
更新对象后,您可以调用ObjectContext.Refresh
方法让 EntityFramework 从数据库中获取对象的最新数据。
关于c# - 保存对象并立即将其取回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19866689/