Một vấn đề NHibernate JOIN khác.NHibernate - nhiều THAM GIA cùng một bảng bằng các phím khác nhau
Tôi đang cố gắng tham gia hai thuộc tính khác nhau từ một bảng bằng hai khóa khác nhau . Nhưng tôi không thể lấy thuộc tính JOIN thứ hai.
Giản dụ -
Lớp học của tôi -
namespace Domain
{
public class Message
{
#region private Members
private string _id;
private string _senderID;
private string _recipientID;
private string _recipientName;
private string _senderName;
#endregion
#region Public Properties
public virtual string ID
{
get { return _id; }
set { _id = value; }
}
public virtual string ID
{
get { return _id; }
set { _id = value; }
}
public virtual string SenderID
{
get { return _senderID; }
set { _senderID= value; }
}
public virtual string RecipientID
{
get { return _recipientID; }
set { _recipientID= value; }
}
public virtual string SenderName
{
get { return _senderName; }
set { _senderName= value; }
}
public virtual string RecipientName
{
get { return _recipientName; }
set { _recipientName= value; }
}
#endregion
#region Constructors
public Message()
{
_id = Guid.NewGuid().ToString();
}
#endregion
}
}
Mapping -
<class name="Domain.Message" table="Messages" >
<id name="ID">
<column name="OID"/>
<generator class="assigned"/>
</id>
<property name="SenderID" unique="true">
<column name="SenderID" unique="true"/>
</property>
<property name="RecipientID" unique="true">
<column name="RecipientID" unique="true"/>
</property>
<join table="CompanyData" optional="true" >
<key column="CompanyID" property-ref="SenderID" />
<property name="SenderName" column="CompanyName" unique="true" lazy="false"/>
</join>
<join table="CompanyData" optional="true" >
<key column="CompanyID" property-ref="RecipientID" />
<property name="RecipientName" column="CompanyName" unique="true" lazy="false"/>
</join>
</class>
nhưng tôi nhận được lệnh SQL sau -
SELECT this_.OID as OID30_0_, this_.SenderID as Sender30_0_,
this_.RecipientID as Recipient30_0_, this_1_.CompanyName as SiteID9_0_
FROM Messages this_
left outer join CompanyData this_1_ on
this_.SenderID=this_1_.CompanyID
left outer join CompanyData this_2_ on
this_.RecipientID=this_2_.CompanyID
Và tôi muốn -
SELECT this_.OID as OID30_0_, this_.SenderID as Sender30_0_,
this_.RecipientID as Recipient30_0_, this_1_.CompenyName as
SiteID9_0_ , this_2_.CompanyName as SiteID10_0_
FROM Messages this_
left outer join CompanyData this_1_ on
this_.SenderID=this_1_.CompanyID
left outer join CompanyData this_2_ on
this_.RecipientID=this_2_.CompanyID
Tôi đang sử dụng NHibernate 3,2
Cảm ơn
Tôi không thể nhìn thấy bất cứ điều gì sai trái với việc lập bản đồ. Bạn có thể đăng mã lớp học không? –
RecipientName được phổ biến khi bạn chạy cái này là gì? Giá trị SenderName? Tôi có khuynh hướng nghĩ rằng đây có thể là một lỗi. nHibernate có thể đang cố gắng tối ưu hóa không chính xác cho bạn. –
Có, bạn nói đúng, RecipientName được điền bằng giá trị SenderName. Tôi có thể làm gì để tắt tối ưu hóa không? –