我正在尝试使用我的一些数据库表(例如 Address
)实现每个层次结构的表继承。我想从 Address
派生 3 个类,它们是 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) |
| .. |
| .. |
| .. |
| .. |
| .. |
+------------------------+
问题是我不断收到错误...
当 Address
是具体,并且包含 OwnerCategory
属性时:
Error 3032: Problem in mapping fragments starting at line 178:Condition member 'addresses.OwnerCategory' with a condition other than 'IsNull=False' is mapped. Either remove the condition on addresses.OwnerCategory or remove it from the mapping.
当 Address
为抽象 且包含 OwnerCategory
属性时:
Problem in mapping fragments starting at line 178:Condition member 'addresses.OwnerCategory' with a condition other than 'IsNull=False' is mapped. Either remove the condition on addresses.OwnerCategory or remove it from the mapping.
当 Address
是具体,并且不包含OwnerCategory
属性时:
'DtcInvoicer.Database.Address' does not contain a definition for 'OwnerCategory' and no extension method 'OwnerCategory' accepting a first argument of type 'DtcInvoicer.Database.Address' could be found (are you missing a using directive or an assembly reference?)
和
Problem in mapping fragments starting at lines 177, 195:EntityTypes Model.Address, Model.EmployeeAddress are being mapped to the same rows in table addresses. Mapping conditions can be used to distinguish the rows that these types are mapped to.
(我已经设置了条件(当 OwnerCategory = 0 时)
当Address
是抽象 并且不 包含OwnerCategory
属性时:
'DtcInvoicer.Database.Address' does not contain a definition for 'OwnerCategory' and no extension method 'OwnerCategory' accepting a first argument of type 'DtcInvoicer.Database.Address' could be found (are you missing a using directive or an assembly reference?)
感谢任何帮助,提前致谢。
最佳答案
由于您在继承条件中使用了 OwnerCategory
,因此无法将其映射到属性。看起来您还应该将 Address
设置为抽象。确保从模型中删除该属性并修改使用它的任何代码。当编译器找不到特定成员时,您提到的非映射错误似乎是标准错误,因此请务必修复这些位置。
关于c# - 每个层次结构继承的 Entity Framework 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7272571/