DeleteObject method is missing in Entity Framework 4.1

限于喜欢 提交于 2019-12-19 04:15:23

问题


This is driving me crazy. I am getting error that

object doesn't contain definition for DeleteObject.

Here is my line of code that produces an error:

ctx.Tanks.DeleteObject(Tank);

I tried to reference another object from another edmx file that my friend has created and then everything is fine, DeleteObject exists. I don't think I miss any references in my project.

And project itself contains edmx file and I used DBContext to create POCOs.

Any ideas?


回答1:


The DbContext API defines DbSets not ObjectSets. DbSet has a Remove method not DeleteObject method. You need to first decide which API you are going to use. If it the ObjectContext or DbContext.




回答2:


  [HttpPost]
        public ActionResult Delete(IEnumerable<int> employeeIdsToDelete)
        {
            var lstemployee = _db.StudentEmployees.Where(x => employeeIdsToDelete.Contains(x.Id));
            foreach (var item in lstemployee)
            {
                _db.StudentEmployees.Remove(item);
            }
            _db.SaveChanges();

            return RedirectToAction("Index");
        }


来源:https://stackoverflow.com/questions/9267991/deleteobject-method-is-missing-in-entity-framework-4-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!