c# - EF6, Circular dependency givs DbPpdateException -
i'm using entity framwork 6, code first.
i have entity team has list of members 1 member team leader.
public class team { public virtual list<member> members { get; private set; } public virtual member teamleader { get; private set; } public team() { members = new list<member>(); } public addmember(member member) { members.add(member); } public addteamleader(member teamleader) { teamleader = teamleader; addmember(teamleader); } }
i want following throws dbupdateexception.
using(var uow = new unitofwork((new datacontext()))) { var team = new team(); team.addmember(new member("adam")); team.addteamleader(new member("david")); uow.teams.add(team); uow.complete(); }
this works not nice , day write first version..
using(var uow = new unitofwork((new datacontext()))) { var theteamleader = new member("david"); uow.members.add(theteamleader); uow.complete(); var team = new team(); team.addmember(new member("adam")); team.addteamleader(theteamleader); uow.teams.add(team); uow.complete(); }
is possible create complete team members , leader , save database 1 savechanges?
the member table have foreign key team table , team table have foreign key member table it's circular dependency , therefore dbupdateexception.
Comments
Post a Comment