c# - 每个层次结构继承的 Entity Framework 表

标签 c# wpf entity-framework

我正在尝试使用我的一些数据库表(例如 Address)实现每个层次结构的表继承。我想从 Address 派生 3 个类,它们是 EmployeeAddressCustomerAddressSupplierAddress

+-------------------+------------------------+
| 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/

相关文章:

c# - 删除文件助手中的引号

c# - 访问不在绑定(bind)列表中的 Datagridview 列

c# - 从代码访问 MVVM Light ViewModelLocator

wpf - ScrollViewer 视口(viewport)高度 VS 实际高度

c# - 如何使用 Entity Framework 根据最大版本选择多条记录

c# - 如何计算 C# 中的 ICollection 中有多少元素

c# - 仅显示 BenchmarkDotNet 的摘要部分

c# - 如何将 DateTime 的 "time"转换为 int?

entity-framework - 如何使用 EF Core 加载导航属性?

ASP.net:由于数据库错误,无法使用网站管理工具