在Entity框架中无法调用DeleteObject - 缺少程序集引用? [英] Can't call DeleteObject in Entity framework - missing an assembly reference?
问题描述
private dbContext db = new dbContext();
public void DeleteAccessDetails(AccessDetails details)
{
db.DeleteObject(details); //这里的错误,因为DeleteObject不被识别
}
这是我的参考: / p>
using System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用MySite.Models;
使用System.Data;
使用System.Data.Objects;
使用System.Web.Mvc;
使用System.Data.Entity;
我以为让System.Data.Entity已经足够引起DeleteObject,但是智能感知几乎是提出任何选项 - 只有Dispose,Entry,SaveChanges和Set
编辑:这里也是我的访问存储库的代码:
Repository rep = new Repository();
AccessDetails paymentUpdate = rep.GetPaymentByID(item.AccessDetailsTableID);
rep.DeleteAccessDetails(paymentUpdate);
编辑2:这是我的参考文件夹的图像:
感谢
EF4.1中的DbContext文档似乎表明它不包括删除方法课程: http:/ /msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=vs.103).aspx ...
这个问题看起来类似 - 可能有些帮助: MVC 3 EF 4.1 dbContext - 删除具有不可空的外键关系的一对多数据对象
I'm trying to delete an object in my asp.net MVC3/Code-first Entity Framework application, but I don't seem to have the necessary options, as it brings up a "does not contain a definition for DeleteObject" error. Anyone know if I'm missing an assembly reference. Here is my repository code:
private dbContext db = new dbContext();
public void DeleteAccessDetails(AccessDetails details)
{
db.DeleteObject(details); //error here as DeleteObject isn't recognised
}
Here are my references:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySite.Models;
using System.Data;
using System.Data.Objects;
using System.Web.Mvc;
using System.Data.Entity;
I thought having System.Data.Entity would have been enough to bring up DeleteObject, but intellisense is hardly bringing up any options - only Dispose, Entry, SaveChanges and Set
Edit: Here is also my code for accessing the repository:
Repository rep = new Repository();
AccessDetails paymentUpdate = rep.GetPaymentByID(item.AccessDetailsTableID);
rep.DeleteAccessDetails(paymentUpdate);
Edit 2: Here is an image of my references folder:
Thanks
The documentation for the DbContext in EF4.1 seems to show that it doesn't include a delete method on that class: http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=vs.103).aspx...
This question looks similar - might be some help: MVC 3 EF 4.1 dbContext - Deleting one-to-many data object with non-nullable foreign-key relation
这篇关于在Entity框架中无法调用DeleteObject - 缺少程序集引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!