Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How to insert a Parent along with it's children in EF Core

$
0
0

In my ASP.NET Core 1.1.1 MVC web app, the Intellisense of the code editor of VS2017 does not recognize .child at line p.child.Add(c1);. What is the correct way of adding a Parent along with it's children.

...
Parent p = new Parent { Name = "some name" , FY = SelectedYear, ... };

Child c1 = new Child { ItemName = "Abc"};
Child c2 = new Child { ItemName = "Rst"};

p.child.Add(c1);
p..child.Add(c2);

_context.Add(p);
_context.SaveChanges();


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>