EF Mapping a table to a hierarchy

When I tried to normalize the database schema and map it in the Entity Framework, I found that in the end it could be a lot of lookup tables. As a result, they will contain only key pairs and values. I would like to combine them into one table, which basically has two columns “Key” and “Value”. For example, I would like the addresses Addresses.AddressType and Person.Gender to point to the same table, but make sure that the navigation properties only return rows that apply to the corresponding object.

EDIT: Oh. I just realized that I left this point:

It seems that the problem is with the TPH type, but all the reading I have shown indicates that you start with fields in the parent and transfer the fields of the inherited children. I have no fields to move here, because usually there will only be two.

You must specify many key-value pairs for the domain. Some of them will change from time to time, others will not. Instead of choosing and choosing, I just want to make everything editable. Due to the number of these kinds of properties that will be used, I would prefer not to maintain a list of enumerations that require recompilation, or ultimately with a large number of lookup tables. So, I thought this might be a solution.

Is there any way to present such a structure in EF4? Or am I barking the wrong tree?

EDIT: , , , , EF. , . , EF?

+3
1

, , . , , . , . , EF. , :

CREATE TABLE KeyValuePairs
(
  Id INT NOT NULL IDENTITY(1,1),
  Key VARCHAR(50) NOT NULL,
  Value NVARCHAR(255) NOT NULL,
  Discriminator VARCHAR(10) NOT NULL,
  Timestamp Timestamp NOT NULL 
)

KeyValuePair Id, Key, Value Timestamp ( concurrency ). .

, EF . AddressType Gender, , , PhoneType. EF, .

hiearchy . , EF . .

+2

Source: https://habr.com/ru/post/1790568/


All Articles