每个层次结构的继承实体框架表 [英] Entity Framework Table per Hierarchy Inheritance

查看:166
本文介绍了每个层次结构的继承实体框架表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现每个层次结构的继承表我的一些数据库表中,例如地址。我想从地址,它们是 EmployeeAddress CustomerAddress SupplierAddress

  + ------------------- + ----- ------------------- + 
|地址|> EmployeeAddress |
+ ------------------- + ------------------------ +
| ID | .. |
| OWNERID |雇员|
| OwnerCategory | (条件:其中= 0)|
| Street_1 | .. |
| Street_2 | .. |
|市| .. |
|省| .. |
|邮编| .. |
+ ------------------- + ------------------------ +
|> CustomerAddress |
+ ------------------------ +
| .. |
|雇员|
| (条件:其中= 1)|
| .. |
| .. |
| .. |
| .. |
| .. |
+ ------------------------ +
|> SupplierAddress |
+ ------------------------ +
| .. |
|雇员|
| (条件:其中= 2)|
| .. |
| .. |
| .. |
| .. |
| .. |
+ ------------------------ +

问题是我不断收到错误...



地址混凝土,并包含 OwnerCategory 属性:




错误3032:问题映射碎片开始行
178:条件成员addresses.OwnerCategory符合条件的其他
不是ISNULL =假'被映射。无论是取消对
addresses.OwnerCategory的条件或从映射删除它。




地址摘要并包含 OwnerCategory 属性:




问题映射碎片开始行178:比其它条件状况会员
'addresses.OwnerCategory'ISNULL =假'
映射。无论是取消对addresses.OwnerCategory或
的条件从映射删除它。




地址混凝土包含 OwnerCategory 属性:




DtcInvoicer.Database.Address'不包含
'OwnerCategory的定义,并没有扩展方法'OwnerCategory接受
类型'DtcInvoicer.Database.Address'的第一个参数可以发现
(是否缺少using指令或程序集引用?)







问题映射碎片开始在177线,195:EntityTypes
Model.Address,Model.EmployeeAddress被映射到相同的行$表地址b $湾映射条件可以用来区分这些类型映射到




(我已经有条件组(当OwnerCategory = 0)



地址摘要做不可以包含 OwnerCategory 属性:




DtcInvoicer.Database。地址不包含
定义'OwnerCategory',没有扩展方法'OwnerCategory接受
型的第一个参数DtcInvoicer.Database.Address可以发现
(是否缺少使用指令或程序集引用?)




任何帮助表示赞赏,谢谢提前。


< DIV CLASS =h2_lin>解决方案

由于您使用的 OwnerCategory 为你的产业,不能被映射到属性的条件。它也像你也应该有地址设置为抽象的。请确保您从模型中删除的财产,并修改这是使用它的任何代码。你提到的非映射错误显示为标准错误时,编译器不能找到一个特定的成员,所以一定要解决这些斑点。


I am trying to implement table per hierarchy inheritance with some of my database tables, e.g Address. I want to derive 3 classes from Address, these are 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 I keep getting errors...

When Address is concrete, and contains the OwnerCategory property:

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.

When Address is abstract and contains the OwnerCategory property:

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.

When Address is concrete, and does not contain the OwnerCategory property:

'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?)

and

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.

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

When Address is abstract and does not contain the OwnerCategory property:

'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?)

Any help is appreciated, thanks in advance.

解决方案

Since you are using OwnerCategory in the condition for your inheritance it can't be mapped to a property. It also looks like you should also have Address set to abstract. Make sure you delete the property from your model and amend any code that was using it. The non mapping errors you mention appear to be the standard error when the compiler can't find a specific member so be sure to fix those spots.

这篇关于每个层次结构的继承实体框架表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆