Entity Framework 1 to 1 relationship Code First Method


/ Published in: C#
Save to your folder(s)

How to create a one to one relationship using the Entity Framework and the Code First Method.

In this example, were creating a 1 to 1 relationship with the Bakery class and the BakeryRecipe class.

Make sure each class has a link to the other class through the virtual instance.
Add the context code to the Context file (BakeryContext.cs in this case).

The context code below is making the Primary key in the BakeryRecipe class, and the Foreign key in the Bakery class.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.