Correct way of mapping a 'one to many' relationship. When having the same relation in multiple entities

c# entity-framework-core orm

Question

Suppose the classes and connections in the following structure:

class Document
{
    public List<Version> DocumentVersions { get; set; }
    // Other properties
}

class Register
{
    public List<Version> RegisterVersions { get; set; }
    // Other properties
}

class Version
{
    public int VersionNumber { get; set; }
    // Other properties
}

When utilizing EF Core, three tables—D, R, and V—will be generated; V will have two FK—one for D and one for R.

My inquiries are:

  • Is the default EF Core method correct? Invalid states where V has no FKs would result from this as both FKs are nillable.
  • After reading this, which nearly provided an answer to my opening query, I now have a new one.
    • Should I make a derived type of V for each of its owners in order to instruct EF to take that course of action? Or is there a way I can tell EF which connections belong to which table and map a single entity to many tables?

It may be important to note that my example is oversimplified and that there are really six entities utilizing the same V object.

1
1
10/4/2018 10:56:58 PM

Accepted Answer

ZZZ_tmp
1
10/12/2018 8:21:27 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow