> 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; }
Still this is a rigid and unmaintainable way to create queries, as
part of the query is stored in the mapping file and has to be enabled on the
session which might execute other queries as well (which perhaps don't
need/require the filter, so you have to switch it off on time). IMHO an
overload of CreateCriteria which accepts another ICriterion would be
preferable (together with a boolean to 'overrule' the complete ON clause
with the predicate, which is also sometimes necessary)
FB
>
>
> 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.
--
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.