Reputation: 655
i am using vs 2012 and dot net 4, i have a model folder that contains my model in my page " Default.aspx " i used
> using MyProjectName.Model;
but when i am trying to delete some data it says " 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);
}
Upvotes: 4
Views: 4685
Reputation: 177133
With DbContext
you can use DbSet<T>.Remove
instead of ObjectContext.DeleteObject
which has the same purpose to delete 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));
}
Upvotes: 3
Reputation: 82096
The issue is DbContext doesn't have a DeleteObject
method, only ObjectContext does, you can get the underlying object context by casting e.g.
((IObjectContextAdapter)context).ObjectContext.DeleteObject
Upvotes: 3