D
D
Denis2015-02-16 15:30:32
Database design
Denis, 2015-02-16 15:30:32

How to implement an "either or" relationship in a table? (checkerboard order)?

Good afternoon.
There is a certain table in which there are two columns "PrivatePersonId" and "JuridicPersonId"
Columns are not part of the key, but have a relationship with each other:

Either one column is filled, or the second.

At the moment, it was decided to move the relationship to a separate table "Seller" with columns
{Id,PrivatePersonId,JuridicPersonId}
And in the main table, leave the "SellerId" column with a link to the ID of the "Seller" table.
Question: is this architecture correct?
In particular, when working with EntityFramework, getting information about the seller is confusing:
if (Obj.Sellser.PrivatePerson != null){
     Console.Writeline(obj.Seller.PrivatePerson.Name);
....}
else
{
   Console.Writeline(obj.Seller.JuridicPerson.Name);
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question