我正在尝试删除我的 asp.net MVC3/Code-first Entity Framework 应用程序中的一个对象,但我似乎没有必要的选项,因为它会出现“不包含 DeleteObject 的定义”错误。任何人都知道我是否缺少装配参考。这是我的存储库代码:
private dbContext db = new dbContext();
public void DeleteAccessDetails(AccessDetails details)
{
db.DeleteObject(details); //error here as DeleteObject isn't recognised
}
以下是我的参考资料:
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;
我认为拥有 System.Data.Entity 就足以调出 DeleteObject,但智能感知几乎没有调出任何选项 - 只有 Dispose、Entry、SaveChanges 和 Set
编辑:这也是我访问存储库的代码:
Repository rep = new Repository();
AccessDetails paymentUpdate = rep.GetPaymentByID(item.AccessDetailsTableID);
rep.DeleteAccessDetails(paymentUpdate);
编辑2:这是我的参考文件夹的图像:
Thanks
DbContext
没有DeleteObject()
方法。相反,使用Remove()
方法从中清除对象DbSet
,然后保存更改。
dbContext db = new dbContext(); // Arrange the context
Department dept = db.Departments.Single(p => p.Id == "1"); // Find the item to remove
db.Departments.Remove(dept); // Remove from the context
b.SaveChanges(); // Delete from the database
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)