OK I can delete a single item in EF6 like this:
public void DeleteUserGroup(MY_GROUPS ug)
{
using (var context = new MYConn())
{
var entry = context.Entry(ug);
if (entry.State == EntityState.Detached)
{
context.MY_GROUPS.Attach(ug);
}
context.MY_GROUPS.Remove(ug);
context.SaveChanges();
}
}
If this method changed from passing a single instance of MY_GROUPS to a List<MY_GROUPS> how would I handle the delete?
Would there be a more efficient way then just doing a foreach and setting the state one at a time?
UPDATE:
I am already using a similar method as above utilizing the RemoveRange method.
However I am getting an error:
The object cannot be deleted because it was not found in the ObjectStateManager.
I'm looking for the best way to attach a list of objects to the context so that I can delete them.