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
Post a Comment