Since it looked like using the criteria directly was going to be my only means of getting the withClause to work. I spent some time implementing a weakly type safe extension class on criteria, and discovered that the problem is simply that the join condition does not get generated when you use the code defined in
QueryOver<TRoot,TRoot> ToRowCountQuery() to count the number of results in the result set. On the other hand if take the entire resultset into memory with List() and count the number of elements their then the join condition is correctly generated. Does anyone know why this is happening? On May 21, 1:22 am, birchoff <[email protected]> wrote: > I see that the ability to use QueryOver to specify a join condition > has been added to NH 3.2 since Alpha1. Is there some special > functionality that was added only to 3.2 to support this feature? From > a quick glance at the source it appears that I should be able to > enable this capability in NH 3.0 till our next release cycle when the > version of NH that we use can be upgraded. > > Unfortunately when I try to use the following code to create an > extension method to bolt on this functionality it does not work. > > public static class QueryOverExtensions > { > public static QueryOver<TRoot,U> JoinQueryOver<TRoot, > TSubType, U>( > this IQueryOver<TRoot, TSubType> queryOver, > Expression<Func<U>> path, Expression<Func<U>> alias, JoinType > joinType, ICriterion withClause) > { > return new ExtendedQueryOver<TRoot, > U>(queryOver.RootCriteria, > queryOver.UnderlyingCriteria.CreateCriteria( > > ExpressionProcessor.FindMemberExpression(path.Body), > > ExpressionProcessor.FindMemberExpression(alias.Body), > joinType, > withClause)); > } > > public static QueryOver<TRoot, U> JoinQueryOver<TRoot, > TSubType, U>( > this IQueryOver<TRoot, TSubType> queryOver, > Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, > JoinType joinType, ICriterion withClause) > { > return new ExtendedQueryOver<TRoot, > U>(queryOver.RootCriteria, > queryOver.UnderlyingCriteria.CreateCriteria( > > ExpressionProcessor.FindMemberExpression(path.Body), > > ExpressionProcessor.FindMemberExpression(alias.Body), > joinType, > withClause)); > } > > public class ExtendedQueryOver<TRoot, TSubType> : > QueryOver<TRoot,TSubType> > { > public ExtendedQueryOver(ICriteria rootImpl, ICriteria > criteria) : base((CriteriaImpl)rootImpl, criteria) > { > > } > } > } > > However, If I use the UnderLyingCriteria property on my QueryOver to > retrieve the criteria and execute CreateCriteria directly I am able to > generate a query with the correct join condition. > > Can someone point me to what I am doing wrong in my effort to get this > working with QueryOver in NH 3.0 or let me know if it is not possible > at all. -- 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.
