15
我想利用NH來映射到EAV/CR數據模型的鬆散解釋的數據模型。使用NHibernate的EAV數據模型
我大部分工作正常,但我正在努力與映射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集合映射到實體實體。
注意EntityAttributes表可以(不)包含給定ENTITYID /屬性Id組合多行:
EntityId AttributeId AttributeValue
-------- ----------- --------------
1 1 Blue
1 1 Green
StringAttributes行看起來像這樣在這個例子中:
StringAttributeId AttributeName
----------------- --------------
1 FavoriteColor
我怎樣纔能有效地將此數據模型映射到我的實體域,以便Entity.Attributes(「FavoriteColors」)返回最喜歡的顏色集合?輸入爲System.String?
是否使用流利? – 2012-04-16 09:07:43
如果您打算通過屬性值查找實體,我不確定sql_variant是否正常工作。你應該試試這個。 – 2012-04-16 09:09:23