DeleteObject does not exist in Context

I use vs 2012 and dot net 4, I have a model folder containing my model on my "Default.aspx" page, which I used

> using MyProjectName.Model; 

but when I try to delete some data, it says that the โ€œDeleteObjectโ€ method does not exist!

 using (var context = new Entities()) { (from ur in context.Module_Users_Info where ur.UserID == comarg select ur).ToList().ForEach(context.DeleteObject); } 
+4
source share
2 answers

Using DbContext you can use DbSet<T>.Remove instead of ObjectContext.DeleteObject , which has the same goal - to remove entities from the database:

 using (var context = new Entities()) { (from ur in context.Module_Users_Info where ur.UserID == comarg select ur) .ToList() .ForEach(ur => context.Module_Users_Info.Remove(ur)); } 
+3
source

Problem DbContext does not have DeleteObject method, only ObjectContext , you can get the context of the base object, for example,

 ((IObjectContextAdapter)context).ObjectContext.DeleteObject 
+3
source

Source: https://habr.com/ru/post/1488877/


All Articles