Cannot remove ManyToMany item
Posted: Thu 17 Feb 2011 15:56
Hello, I have two entities: Utente and Gruppo which are ManyToMany related.
In the designer I can create the entities correctly: they are linked with a dotted line showing a "*" on both sides.
When I try to delete a relation this way:
I get an exception saying: "Could not modify EntitySet".
What am I doing wrong?
Thanks
In the designer I can create the entities correctly: they are linked with a dotted line showing a "*" on both sides.
When I try to delete a relation this way:
Code: Select all
public bool RemoveUserFromGroup(string user, string group)
{
Utente utente = context.Utenti.SingleOrDefault(u => u.UserName == user);
Gruppo gruppo = context.Gruppi.SingleOrDefault(g => g.UserGroup == group);
if (utente == null || gruppo == null) return false;
utente.Gruppi.Remove(gruppo);
context.SubmitChanges();
return true;
}
What am I doing wrong?
Thanks