So your Publications class is mapped with a join to Statements. If you want your query to not include that inner join then you need to create another class, say RoPublications, that is set as read only and does not have the join, then use that class for your count.
John Davidson On Fri, Sep 9, 2011 at 10:51 AM, csetzkorn <[email protected]> wrote: > Hi, > > Thanks for the reply. I copy and paste the question on SA below. Not > sure why it is incomplete - please let me know why. Thanks! > > I am using this query: > > return from oi in NHibernateSession.Current.Query<BlaInteraction>() > select new BlaViewModel > { > ... > > NoPublications = oi.Publications.Count(), > > ... > }; > > BlaInteraction contains an IList of publications (i.e. entities). To > determine the number of publications one does not really need to do > all the joins for a publication. Can I prevent nhibernate from using > joins in the generated sql (e.g. using projection???) somehow? > > Thanks. > > Christian > > PS: > > This is what NH produces (slightly adapted): > > select cast(count(*) as INT) from > RelationshipStatementPublications publicatio21_, Publication > publicatio22_ inner join Statements publicatio22_1_ on > publicatio22_.StatementId=publicatio22_1_.DBId where > publicatio21_.StatementId = 22762181 and > publicatio21_.PublicationId=publicatio22_.StatementId > > This is what would be sufficient: > > select cast(count(*) as INT) from > RelationshipStatementPublications publicatio21_ where > publicatio21_.StatementId = 22762181 > > On Sep 9, 2:24 pm, John Davidson <[email protected]> wrote: > > If you really want an answer here please post the details in your message > > rather than in StackOverflow. I checked StackOverflow and your query > there > > is incomplete. Please try again. > > > > John Davidson > > > > On Fri, Sep 9, 2011 at 9:01 AM, csetzkorn <[email protected]> wrote: > > > 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.
