entity framework - Navigation Property to 'Child object' in 'Parent child collection' on 'Parent' -


is there way save child object in parents child object collection , setting navigation property on parent without round tripping database? example below doesn't work

public class parent {     int id { get; set; }     int? childid { get; set; }     child child { get; set; }      public virtual icollection<child> children { get; set; } } public class child {     int id { get; set; }     public parent parent { get; set; } }  ....  var p = new parent(); var c = new child();  p.child = c; p.children.add(c);  context.set<parent>().add(p); context.savechanges(); 

edit

the example above throws error when 'savechanges()' called.

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


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -