2011-11-14 10 views
5

एक अन्य NHibernate जॉइन समस्या।एनएचबेर्नेट - अलग-अलग कुंजियों द्वारा एक ही तालिका में एकाधिक जॉइन

मैं अलग दो कुंजी द्वारा एक मेज से दो अलग-अलग गुण शामिल होने के लिए कोशिश कर रहा हूँ। लेकिन मुझे दूसरी जॉइन संपत्ति नहीं मिल सकती है।

सरलीकृत उदाहरण -

मेरी कक्षा -

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

मानचित्रण -

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

लेकिन मैं निम्नलिखित एसक्यूएल मिल -

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 

और मैं चाहता हूँ -

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 

मैं NHibernate 3.2

धन्यवाद

+0

मैं कुछ भी मानचित्रण के साथ गलत नहीं देख सकता। क्या आप कक्षा कोड भी पोस्ट कर सकते हैं? –

+0

जब आप इसे चलाते हैं तो प्राप्तकर्ता नाम को पॉप्युलेट किया जा रहा है? प्रेषक नाम मूल्य? मुझे लगता है कि यह एक बग हो सकता है। nHibernate आपके लिए गलत तरीके से अनुकूलित करने का प्रयास कर रहा है। –

+0

हां, आप सही हैं, प्राप्तकर्ता नाम प्रेषक नाम से भरा है। क्या मैं कुछ भी कर सकता हूं जो अनुकूलन को बंद कर सकता है? –

उत्तर

2

जाहिर है, यह NHibenate मैपिंग के साथ पल में नहीं किया जा सकता का उपयोग कर रहा हूँ। Spencer Ruport द्वारा सुझाए गए निकटतम समाधान, दृश्य को देखने और उस पर ऑब्जेक्ट को मानचित्र बनाना है।

3

मैं उसी समस्या का हल ढूंढने के लिए पूरे दिन इंटरनेट के माध्यम से छिप रहा था। जो मैंने पाया वह hibernate board पर धागा है। मैंने Ashkan Aryan से समाधान लिया। तो अगर किसी और को समाधान के बारे में सिरदर्द हो जाता है और विचारों का उपयोग नहीं करना चाहता तो मैं अपना कोड पोस्ट करूंगा जिसका मैं अब उपयोग कर रहा हूं।

मैं तो दृश्य बनाने के लिए बहुत भ्रामक है 1 से 12 एक ही मेज पर मिलती है करने के लिए उपयोग करने के लिए है।

private void addParagraphsQuery(DetachedCriteria sourceQuery, List<ParagraphContentArgument> paragraphsArguments) 
{ 
    DetachedCriteria dc; 
    Conjunction conjunction = Restrictions.Conjunction(); 
    string alias = string.Empty; 

    if (paragraphsArguments != null && paragraphsArguments.Count > 0) 
    { 
     for (int i = 0; i < paragraphsArguments.Count; i++) 
     { 
      alias = "p" + i.ToString(); 
      dc = DetachedCriteria.For<Document>().SetProjection(Projections.Id()); 
      dc.CreateAlias("paragraphList", alias); 
      dc.Add(Restrictions.Eq(alias + ".paragraphSectionTemplate", paragraphsArguments[i].ParagraphTemplate)); 
      dc.Add(Restrictions.Like(alias + ".content", paragraphsArguments[i].Argument, MatchMode.Anywhere)); 
      conjunction.Add(Property.ForName("id").In(dc)); 
     } 
    } 
    sourceQuery.Add(conjunction); 
} 

सादर,

मारिउज़

संबंधित मुद्दे