我正在尝试利用 NH 映射到对 EAV/CR 数据模型进行松散解释的数据模型。
我的大部分工作都在工作,但在映射 Entity.Attributes 集合时遇到了困难。
以下是有问题的表格:
--------------------
| Entities |
--------------------
| EntityId PK |-|
| EntityType | |
-------------------- |
-------------
|
V
--------------------
| EntityAttributes | ------------------ ---------------------------
-------------------- | Attributes | | StringAttributes |
| EntityId PK,FK | ------------------ ---------------------------
| AttributeId FK | -> | AttributeId PK | -> | StringAttributeId PK,FK |
| AttributeValue | | AttributeType | | AttributeName |
-------------------- ------------------ ---------------------------
AttributeValue 列实现为 sql_variant 列,我已经为它实现了 NHibernate.UserTypes.IUserType。
我可以创建一个 EntityAttribute 实体并直接将其持久化,以便层次结构的一部分正常工作。
我只是不确定如何将 EntityAttributes 集合映射到 Entity 实体。
请注意,对于给定的 EntityId/AttributeId 组合,EntityAttributes 表可以(并且确实)包含多行:
EntityId AttributeId AttributeValue
-------- ----------- --------------
1 1 Blue
1 1 Green
对于此示例,StringAttributes 行如下所示:
StringAttributeId AttributeName
----------------- --------------
1 FavoriteColor
如何有效地将此数据模型映射到我的实体域,以便 Entity.Attributes("FavoriteColors") 返回最喜欢的颜色集合?键入为 System.String?