Can anyone tell me whether this extra where clause is a bug or by design (what is the explanation)? Just wandering whether there is any hope of this changing or if I really need to come up with a plan B (again)
On 3 Aug, 17:25, julianjelfs <[email protected]> wrote: > I can't do that. It has to all be done as part of the same query > because this is part of a larger criteria query (which involves lots > of other bits of filtering, projecting, paging sorting etc), which > will fall apart if I split it. > > Is it not a bug though, that I have specified no restriction on the > main criteria but it has added a where clause? It seems that the > filter definition should only be instructing it to qualify the join, > not the main criteria. > > Perhaps this is just the way it is, but it seems I am frustratingly > close to having what I want and that extra bit in the where clause > seems unnecessary. > > Thanks again for the help so far .... > > On Aug 3, 5:12 pm, Jason Meckley <[email protected]> wrote: > > > > > the problem is your criteria, not filter. just query the assessments. > > then query the categories. > > > session.EnableFilter("ByCategory").SetParameter("id", 1); > > var assessments = > > session.CreateCriteria<Assessment>().List<Assessment>(); > > foreach(var assessment in assessments) > > { > > var categories = assessment.Categories; > > > } > > > On Aug 3, 11:28 am, julianjelfs <[email protected]> wrote: > > > > Ooooh very close. This is nearly perfect except that is seems to be > > > adding the condition to the where clause as well now, so I am getting: > > > > SELECT ... > > > FROM Assessment this_ > > > left outer join Categories impactcate1_ > > > on this_.AssessmentId = impactcate1_.AssessmentId > > > and impactcate1_.CategoryID = 1 > > > WHERE impactcate1_.CategoryID = 1 > > > > This is with the following criteria: > > > > session.EnableFilter("ByCategory").SetParameter("id", 1); > > > > session.CreateCriteria(typeof (Assessment)) > > > .CreateCriteria("Categories", JoinType.LeftOuterJoin) > > > .List(); > > > > If I can just get rid of that where clause I will have exactly what I > > > want. > > > > Thanks very much for the help so far - any help with the last problem > > > would be fantastic. > > > > On Aug 3, 3:04 pm, Jason Meckley <[email protected]> wrote: > > > > > filters may be the option you are looking for > > > > <set name="Categories"> > > > > <filter name="ByCategory" condition="CategoryId = :id"/> > > > > </set> > > > > .... > > > > <filter-def name="ByCategory"> > > > > <param name="CategoryId" type="long" /> > > > > </filter-def> > > > > > session.EnableFilter("ByCategory").SetParameter("id", 1); > > > > session.Get<Assesment>(2); > > > > > var onlyCategoriesWithIdEqualToOne = Assesment.Categories; > > > > > On Aug 3, 9:07 am, julianjelfs <[email protected]> wrote: > > > > > > Hi, > > > > > > Is there a way to restrict the join performed to populate a set using > > > > > a dynamic variable or a parameter. The set mapping allows me to > > > > > specify a "where" attribute but I need it to look something like this: > > > > > > <set name="Categories" table="Categories" where="CategoryId = :id" > > > > > > ... > > > > > </set> > > > > > > rather than having a static value. > > > > > > If I add this condition as a restriction to the overall criteria, the > > > > > restriction gets added to the where clause of the query rather than as > > > > > a condition of the join. This is not quite the same thing and not what > > > > > I want. > > > > > > session.CreateCriteria(typeof (Assessment)) > > > > > .CreateCriteria("Categories", JoinType.LeftOuterJoin) > > > > > .Add(Restrictions.Eq("CategoryId", 1)) > > > > > .List(); > > > > > > gives me something like: > > > > > > SELECT ... > > > > > FROM Assessment this_ > > > > > left outer join Categories impactcate1_ > > > > > on this_.AssessmentId = impactcate1_.AssessmentId > > > > > WHERE impactcate1_.CategoryID = 1 > > > > > > whereas what I need is: > > > > > > SELECT ... > > > > > FROM Assessment this_ > > > > > left outer join Categories impactcate1_ > > > > > on this_.AssessmentId = impactcate1_.AssessmentId > > > > > and impactcate1_.CategoryID = 1 > > > > > > I can't think of any way round this at the moment, so any ideas would > > > > > be appreciated. > > > > > > Thanks, > > > > > > Julian. -- 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.
