i have 2 entities each with a relating c# class. I set up a navigation property on table A to contain a reference to many items in table B. When i make a new table A class object i need to be able to create the collection of table B objects in table A. How do i set up the navigation property in the table A c# class?
Share
Navigation properties are simple in EF. The example below shows how a navigation property would look:
Where
Foorepresents tableA andBarrepresents tableB. They key word for the navigation property is virtual which enables lazy-loading by default. This is assuming you’re using EF4.1 Code First.EDIT
Off the top of my head, this should be a good starting template for you:
Then you would implement the other logic in your business objects. The entities are supposed to be lightweight and at most should have data attributes. I prefer to use the fluent mappings through the OnModelCreating though.
Here are a few good references:
MSDN – EF 4.1 Code First
Code First Tutorial