This is normal (though often confusing) behaviour of NHibernate when using a query which contains a Join. You basically get as many items back when you would for a SQL result. I created a wrapper function around the list to only return met the unique items. So that when I call Customer Join Purchases and want to iterate over the customers I do only visit every customer object once. The same happens when you use SetFetchmode Join in a ICriteria query. I am not sure why they designed it like this, because it is puzzling at first but it seems consistent. When you add all the results to a set it will automatically un-duplicate. Have had big issues when setting relationships using lists rather than sets with this thing! Suddenly when using join load performance optimisations I got duplicates in the collections, just like you describe above.
Hope this helps, Theo On Aug 15, 8:34 am, Kasi <[email protected]> wrote: > The query (in the code), while running on SQL server returns the > following result. > > 53 10 _heading Supplier Sustainability > Assessment 101 > 53 10 _heading FR_SUST 102 > 54 10 _tabHome Home 101 > 55 10 _tabQuestionnaire Questionnaire 101 > 56 10 _tabResults Results 101 > 57 10 _tabResourcesFAQ Resources & FAQs > 101 > > But while running the code on visual studio returns the first row > twice and instead of the second row - > > 53 10 _heading Supplier Sustainability > Assessment 101 > 53 10 _heading Supplier Sustainability > Assessment 101 > 54 10 _tabHome Home 101 > 55 10 _tabQuestionnaire Questionnaire 101 > 56 10 _tabResults Results 101 > 57 10 _tabResourcesFAQ Resources & FAQs > 101 > > I have no idea as to why. > > Code. > > private IList<WebpageElement> GetWBById(int id) > { > using (ISession session = NHibernateHelper.OpenSession()) > using (ITransaction transaction = > session.BeginTransaction()) > { > try > { > string sql = @" > SELECT > web_page_html_element.html_element_id, > web_page_html_element.web_page_id, > html_element.html_element_name, > Html_Element_Text.html_element_txt, > Html_Element_Text.language_code > FROM Web_Page_Html_Element INNER JOIN > Html_Element ON > Web_Page_Html_Element.html_element_id = > Html_Element.html_element_id INNER JOIN > Html_Element_Text ON > Html_Element.html_element_id = Html_Element_Text.html_element_id > WHERE (Web_Page_Html_Element.web_page_id > = :id)"; > > ISQLQuery query = > (ISQLQuery)session.CreateSQLQuery(sql) > .SetInt32("id", id); > var list = > query.AddEntity(typeof(WebpageElement)).List<WebpageElement>(); > return list; > } > finally > { > transaction.Commit(); > } > } > > } > > WebpageElement.CS > public class WebpageElement > { > public virtual int Id { get; set; } > public virtual int WebpageId { get; set; } > public virtual string Name { get; set; } > public virtual string Text { get; set; } > public virtual string LanguageCode { get; set; } > > public WebpageElement() { } > } > > WebpagElement.hbm.xml > <class name="WebpageElement" table="web_page_html_element"> > <id name="Id" column="html_element_id"> > <generator class="native"/> > </id> > <property name ="WebpageId"> > <column name="web_page_id"></column> > </property> > <join table="html_element"> > <key column="html_element_id" /> > <property name="Name"> > <column name="html_element_name" /> > </property> > </join> > <join table="html_element_text"> > <key column="html_element_id"/> > <property name="Text"> > <column name="html_element_txt" /> > </property> > <property name="LanguageCode"> > <column name="language_code" /> > </property> > </join> > </class> -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
