本文介绍了删除实体框架的单个记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用实体框架从聘请表中删除一条记录?
How to delete a single record from employ table using Entity Framework?
推荐答案
这是没有必要先查询对象,你可以将其连接到其ID的上下文。
像这样的:
It's not necessary to query the object first, you can attach it to the context by its id.Like this:
var employer = new Employ { Id = 1 };
ctx.Employ.Attach(employer);
ctx.Employ.Remove(employer);
ctx.SaveChanges();
这篇关于删除实体框架的单个记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!