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.

Reply via email to