我看了一些關於後取=加盟 - http://nhforge.org/blogs/nhibernate/archive/2009/04/09/nhibernate-mapping-lt-many-to-one-gt.aspx(ser4ik.livejournal.com/2505.html) 所以我有一些問題,Forexample我有類取=加入到表一類NHibernate的
<class name="AttributesInf" table="attr_inf">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Name" />
<property name="Desc"/>
</class>
和
<class name="AttributeValue" table="attr_val">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Value" />
<many-to-one name="AttrName" column="attrId"/>
</class>
如果我用這個映射而不集讀取= 「加入」 我得到的SQL:
Select av.Id, av.Value, av.attrId From attr_val av where av.Id=...()
,並像當年獨立的SQL查詢後:
Select * From attr_inf where Id = av.attrId
所以我的結果是:
class AttrinuteInf
{
int Id;
string Name;
string Desc;
}
class AttributeValue
{
int Id;
string Value;
AttributeInf AttrName;
}
如果我設置取= 「加入」 然後我得到一個查詢:
Select u.Id, u.UserName, u.BlogId, b.Id, b.BlogName, b.BlogAuthor, b.BlogMsg
from Users u
Left outer join Blogs b
On u.BlogId=b.Id
Where u.Id = ...
所以我期望得到一個分類:
class AttributeValue
{
int Id;
string Value;
string Name;
string Desc;
}
但是我有同樣的結果,如果我沒有設置提取「加入」。
這樣好嗎? 有沒有辦法直接從類maped獲得屬性爲<many-to-one>
? (而不是AttrName.Name,只是名稱)
說明:映射
部分上面設置不顯示我的真正的問題。 我想映射一些實體爲IDictionary<string,AttributeValue>
。 我把它映射爲
<map name="Attributes" table="attr_val" lazy="true" cascade="all-delete-orphan" inverse="true">
<key column="item_id"></key>
<index column="name"></index> //I don't have that item in class AttributeValue, that is why I try to get it from other table
<one-to-many class="AttributeValue"/>
</map>
我明白了,謝謝。但那我能做什麼? – Kate 2009-10-09 12:28:22
我知道你的映射對於常規的Hibernate是不正確的,我不確定NHibernate。我沒有看到你的聯繫...對不起,我現在沒有一個測試環境來幫助你:-( – KLE 2009-10-09 12:51:05