c# - Unable to determine a valid ordering for dependent operations with assigning self as parent -


i getting error below when try assign parent on insert.

unable determine valid ordering dependent operations. dependencies may exist due foreign key constraints, model requirements, or store-generated values.

code below. thought guess not. how can on insert?

public class team {      public int? teamparentid { get; set; }      [foreignkey("teamparentid")]     public virtual team teamparent { get; set; }      public virtual icollection<team> teams { get; set; } } 

where error happens

    divisionteam.team.teamparent = divisionteam.team;   if (divisionteam.id == 0)             {                 _divisionteamsrepository.add(divisionteam);             }              unitofwork.commit(); 

datacontext.cs

modelbuilder.entity<team>()     .hasoptional(p => p.teamparent)     .withmany(p => p.teams)     .hasforeignkey(q => q.teamparentid); 

how can accomplish this?

it seems way setting teams creating cycle, "impossible" "save" ef.

if asking how yo can accomplish you'd have save team no parent , after savechanges() method assign id teamparentid, this:

var team = new team(....);  db.teams.add(team);  team.teamparentid = team.id;  db.savechanges(); 

i know seems convoluted enough, it's way can think of. hope helps you


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -