需要NHibernate查询帮助

时间:2011-10-17 16:19:03

标签: tsql nhibernate nhibernate-criteria

是否可以将以下查询转换为ICriteria或LINQ,如果是,如何?

    SELECT Test.personid
    FROM 
    (
        SELECT r.PersonId AS personid, e.ActivityId
        FROM Event e
        INNER JOIN Registration r ON e.Id = r.EventId
        WHERE e.ActivityId IN (1, 2)
        GROUP BY r.PersonId, e.ActivityId
    ) AS Test

    GROUP BY Test.personid
    HAVING COUNT(Test.ActivityId) >= 2

1 个答案:

答案 0 :(得分:0)

var result = from r in session.Query<Registration>()
             where r.Event.ActivityId == 1 || r.Event.ActivityId == 2
             group r by r.Person into g
             where g.Min(x => x.Event.ActivityId) != g.Max(x => x.Event.ActivityId)
             select g.Key

以下状态,将所有在其中具有不同activityIds的人员等同于

ActivityId == 1 || ActivityId == 2
Having Count(r.Event.ActivityId) >= 2