实体框架中 Hibenate.saveOrUpdate() 的等效项是什么
在实体框架中,您必须编写大量代码来保存或更新单个实体:
using (DataContext context = new DataContext())
{
context.Task.Attach(task);
if (task.ID == 0)
{
context.ObjectStateManager.ChangeObjectState(task, System.Data.EntityState.Added);
}
else
{
context.ApplyOriginalValues(task.GetType().Name, task);
}
context.SaveChanges();
}
在 hibernate 中,它只是 saveOrUpdate()
这不是为了偷懒,而是为了使其简短而干净。
In entity framework you have to write a lot of code for saving or updating a single entity:
using (DataContext context = new DataContext())
{
context.Task.Attach(task);
if (task.ID == 0)
{
context.ObjectStateManager.ChangeObjectState(task, System.Data.EntityState.Added);
}
else
{
context.ApplyOriginalValues(task.GetType().Name, task);
}
context.SaveChanges();
}
in hibernate it is just saveOrUpdate()
This is not about being lazy, it is about making it short and clean.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有同等的。你真的必须这样写:
There is no equivalent. You really have to write it like: