English 中文(简体)
fetch=参加一年级的表格
原标题:fetch=join to tables to one class NHibernate
  • 时间:2009-10-09 12:03:24
  •  标签:

I have read some post about fetch=join - http://nhforge.org/blogs/nhibernate/archive/2009/04/09/nhibernate-mapping-lt-many-to-one-gt.aspx (ser4ik.livejournal.com/2505.html) So I have some question, Forexample I have class

<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> 

如果我使用这一地图时没有打上“灰色”,我就拿到了q子。

Select av.Id, av.Value, av.attrId From attr_val av where av.Id=...()

以及 after then separate sql queries like:

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”,我就有一个问题:

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;
}

但是,我的结果与我没有确定“参与”的理由相同。

Is this all right? Are there any way to get properties from class maped as <many-to-one> directly? (not as AttrName.Name, but simply Name )

解释:

Part of mapping set above don t show my real problem. I want to map some entity as IDictionary<string,AttributeValue>. I map it as

<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>
最佳回答

这是你想做的事情。 利用fetch=join只是急切地把关系的许多方面装上了。 在这两起案件中,你最后用同样的物体返回。 否则,NHibernate将 la升相关实体的负荷(因此,你会收到第二点)。 通过使用fetch=join,你一度要求整个物体关系,但是,它仍会把物体同没有脂肪的物体分开。

问题回答

这并不是你描述的。 根据你的要求,贵实体不会改变。

您将获得贵主要实体的事例清单,而协会与另一实体的联系是紧凑的。 因此,如果你在法典中看到协会,你就会发现这些价值观。

如果你不提,你就无法进入这些领域,因为无法从数据库中检索。

I don t understand your question. The fetch-join attribute just defines how the sql that NHibernate generates to retrieve instances of your classes, should look like. It has nothing to do with what will be returned. NHibernate will translate the recordset (that is the result of the query) to correct instances of your classes.

如果你只是想找回一部分实体(例如名称),那么你就不得不写一个《总部协定》的问询,或者使用《公约》的《公约》文本,并可能使用预测。





相关问题
热门标签