When you say "child of statement", do you mean that it "derives from statement"?
The RelationshipStatementPublication class (in strict terms, not an entity) seems unnecessary now. According to the mapping , it seems you are not using it anyway. Whey you say hydrates, do you really mean that? The initial SQL query you showed does not indicate any hydrating. /G 2011/9/14 csetzkorn <[email protected]> > Ok let me try to explain this again – maybe I was not very clear at > the beginning. Sorry! > > I have a class BlaInteraction which is a child of statement. Each > statement has an IList<Publication>. This relationship is also part of > the domain model to make it future proved: > > public class RelationshipStatementPublication : Entity > { > public virtual Statement Statement { get; set; } > public virtual Publication Publication { get; set; } > } > > In my statement mapping I have: > > mapping.HasManyToMany(x => > x.Publications).Table("RelationshipStatementPublications"); > > My ‘naive’ approach to map a BlaInteraction to a viewmodel and count > the number of publications for each BlaInteraction is this: > return from oi in NHibernateSession.Current.Query<BlaInteraction>() > select new BlaViewModel > { > ... > NoPublications = oi.Publications.Count(), > ... > }; > > This does not scale as hnibernate creates sql code that hydrates each > publication of each (TOP n) BlaInteraction to JUST count the number of > publications. This is what I would like to prevent as removing the > ‘hydration joins’ by hand optimising the sql code scales things. > > Please note that I do not want to use SQL as I am trying to use IQuery > to make use of Telerik's 'Linq-based expression engine' which > generates all the 'stuff' for filtering, paging and sorting. > > Another recent (failed) attempt was this: > > return from oi in NHibernateSession.Current.Query<BlaInteraction>() > select new BlaViewModel > { > ... > //NoPublications = > NHibernateSession.Current.QueryOver<BlaInteraction>().Where(x => > x.Statement.Id == > oi.Id).Select(Projections.RowCount()).SingleOrDefault<int>(), > NoPublications = NHibernateSession.Current.CreateSQLQuery("select > count(distinct PublicationId) from > dbo.RelationshipStatementPublications where StatementId > = :StatementId").SetParameter("StatementId", > oi.Id).UniqueResult<int>(), > ... > }; > > The stuff commented out works but does not make sense. I tried this > due to a recent SO comment. > > Thanks. > > Christian > > > On Sep 14, 11:08 am, Gunnar Liljas <[email protected]> wrote: > > 1. The join is correct. You ask for the number of publications belonging > to > > a specific BlaInteraction. That is what the SQL expresses. > > 2. Is it really important? > > 3. If it is, add the interaction id as a readonly property on the > > publication, and query on that. > > > > /G > > > > 2011/9/9 csetzkorn <[email protected]> > > > > > Hi experts, > > > > > Could you please be so kind and have a look at this: > > > > >http://stackoverflow.com/questions/7359783/prevent-unnecessary-cross-. > .. > > > > > Thanks. > > > > > Christian > > > > > -- > > > 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. > > > > > > -- > 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. > > -- 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.
