Entity Framework table for hierarchy inheritance

I am trying to implement a table to inherit hierarchy with some of my database tables, such as Address . I want to get 3 classes from Address , this is EmployeeAddress , CustomerAddress , SupplierAddress .

 +-------------------+------------------------+ | Address |> EmployeeAddress | +-------------------+------------------------+ | ID | .. | | OwnerID | EmployeeID | | OwnerCategory | (condition: where = 0) | | Street_1 | .. | | Street_2 | .. | | City | .. | | Province | .. | | PostalCode | .. | +-------------------+------------------------+ |> CustomerAddress | +------------------------+ | .. | | EmployeeID | | (condition: where = 1) | | .. | | .. | | .. | | .. | | .. | +------------------------+ |> SupplierAddress | +------------------------+ | .. | | EmployeeID | | (condition: where = 2) | | .. | | .. | | .. | | .. | | .. | +------------------------+ 

The problem is that I keep getting errors ...

If Address concrete and contains the OwnerCategory property:

Error 3032: a problem with displaying fragments, starting from line 178: Addresses of a condition participant .OwnerCategory 'with a condition other than "IsNull = False". Either remove the condition on address.OwnerCategory or remove it from the mapping.

When Address is abstract and contains the OwnerCategory property:

Problem when displaying fragments starting from line 178: a member of the 'addresses.OwnerCategory' condition with a condition other than 'IsNull = False' is displayed. Or delete the condition by address. OwnerCategory or remove it from the display.

If Address specific and does not contain the OwnerCategory property:

'DtcInvoicer.Database.Address' does not contain a definition for 'OwnerCategory' and no extension method 'OwnerCategory' accepts, you can find the first argument of the type "DtcInvoicer.Database.Address" (do you miss using directive or assembly reference?)

and

Problem when displaying fragments starting from lines 177, 195: EntityTypes Model.Address, Model.EmployeeAddress are displayed in the same lines in table addresses. Matching conditions can be used for the string for which these types are displayed.

(I already have a condition set (when OwnerCategory = 0)

When Address abstract and does not contain the OwnerCategory property:

'DtcInvoicer.Database.Address' does not contain a definition for 'OwnerCategory' and no extension method 'OwnerCategory' accepts, you can find the first argument of the type "DtcInvoicer.Database.Address" (do you miss using directive or assembly reference?)

Any help is appreciated, thanks in advance.

+6
source share
1 answer

Since you are using OwnerCategory in a condition for your inheritance, it cannot be matched to a property. It looks like you should also have an Address for the abstract. Be sure to remove the property from your model and make corrections to any code that used it. Mentioned non-referenced display errors are a standard error when the compiler cannot find a specific member, so be sure to correct these places.

+7
source

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


All Articles