Cannot use collections with InExpression

I just went deep into NHibernate, and I am having problems with one of the more difficult questions (to me!) That I have to write. Scenario:

I have a Staff object that has a Skills collection. I would like to pass the list of “Skills” for the request (for example, if I want only people who can either “Smoke”, or “Code”, or both) and return the list of relevant employees, but I have a bit of a problem ....

What I have objectively:

public class StaffMember : Resource
{
    public virtual string EmployeeId { get; set; }      

    public virtual bool IsTeamLeader { get; set; }

    public virtual StaffMember TeamLeader { get; set; }

    public virtual IList<Skill> Skills { get; set; }
}

public class Skill : BaseDomainObject
{
    public virtual string Name { get; set; }
}

And I think that SQL will look something like this:

select distinct st.*
from staff st, resource re
inner join staffskills sks on re.id = sks.staffresourceid
inner join skill ski on ski.id = sks.skillid
where st.resourceid = re.id
and ski.id in (1,2,3,4)

"Expression.InG" ( "" , skillsSearchList) " , , (, , !)... ?

+3
1

.CreateAlias("Skills", "sks")
.Add(Restrictions.In("sks.id", skillIdList))

, . , sql , .

, , .SetResultTransformer(new DistinctRootEntityResultTransformer()), .

+5

Source: https://habr.com/ru/post/1733260/


All Articles