Back to Devexpress

Set a One-to-Many Relationship (EF 6)

expressappframework-113635-getting-started-in-depth-tutorial-winforms-webforms-business-model-design-business-model-design-with-entity-framework-6-set-a-one-to-many-relationship-ef.md

latest3.9 KB
Original Source

Set a One-to-Many Relationship (EF 6)

  • Jul 07, 2021
  • 3 minutes to read

In this lesson, you will learn how to set a one-to-many relationship between business objects. The Contact and Department business objects will be related by a one-to-many relationship. You will then learn the basics of automatic user interface construction for referenced objects.

Note

Before proceeding, take a moment to review the following lessons:

Tip

If you create a new Department and then create a new Contact in the Contacts collection, an associated Department is not immediately visible in the Detail View of the newly created Contact. The link between these objects is added later, when you save the Contact. You can change this behavior using the XafApplication.LinkNewObjectToParentImmediately property. When it is set to true , the link will be created and saved immediately after you click New.

You can see the code demonstrated in this lesson in the MySolution.Module | Data | Contact.cs (Contact.vb) and Department.cs (Department.vb) files of the EF Demo (Code First) installed with XAF. By default, the EF Demo (Code First) application is installed in %PUBLIC%\Documents\DevExpress Demos 21.2\Components\eXpressApp Framework\EFDemoCodeFirst.

Next Lesson: Initialize a Property After Creating an Object (EF 6)

See Also

Relationships Between Entities in Code and UI (EF 6)