DeleteObject 方法没有出现
这是我删除链接的代码。当我尝试 db.deleteobject.. 时,deleteobject 方法没有显示在那里。我应该怎么办。
[HttpPost]
public ActionResult LinkDelete(int id)
{
AralContainer db = new AralContainer("VefatilaniCS");
Link lnk = db.Links.Where(x => x.Id == id).SingleOrDefault();
db.Links.DeleteObject(lnk); // This is the line i got error
db.SaveChanges();
return View();
}
This is my code to delete a link. When i try to db.deleteobject.. deleteobject method is not shown in there. What should i do.
[HttpPost]
public ActionResult LinkDelete(int id)
{
AralContainer db = new AralContainer("VefatilaniCS");
Link lnk = db.Links.Where(x => x.Id == id).SingleOrDefault();
db.Links.DeleteObject(lnk); // This is the line i got error
db.SaveChanges();
return View();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这个:
Where().Single()实际上返回的是DbSet,这不是你想要的:)
use this:
Where().Single() is actually returning you DbSet which is not what you want :)
可能您忘记添加对某些程序集的引用。检查您的网络应用程序是否具有以下引用:
并且,顺便说一下,System.Data.Entity没有任何DeleteObject,只有Remove()
Probably you forgot to add reference to some assemblies. Check if your web app has the following references:
And, by the way System.Data.Entity doesn't have any DeleteObject, only Remove()