fetch =joinに関するいくつかの投稿を読みました-http: //nhforge.org/blogs/nhibernate/archive/2009/04/09/nhibernate-mapping-lt-many-to-one-gt.aspx(ser4ik.livejournal。 com / 2505.html)それで、私はいくつかの質問があります、例えば私はクラスを持っています
<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>
set fetch = "join"なしでこのマッピングを使用すると、次の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;
}
fetch = "join"を設定すると、次の1つのクエリが返されます。
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 = ...
だから私は1つのクラスを取得することを期待しています:
class AttributeValue
{
int Id;
string Value;
string Name;
string Desc;
}
ただし、fetchを「join」に設定しない場合と同じ結果になります。
これで大丈夫ですか?クラスからプロパティを<many-to-one>
直接マップされたものとして取得する方法はありますか?(AttrName.Nameとしてではなく、単に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>