0

我正在编写以下内容作为 NHibernate 查询,但找不到使用 QueryOver 作为 HQL 的解决方案:-

IQuery query = SessionFactoryContext.GetCurrentSession()
    .CreateSQLQuery(
@"SELECT s.UserID,
    Username,
    Email,Password,
    FirstName,
    LastName,
    Address1,
    Address2,
    City,
    County,
    PostalCode,
    Country 
FROM [dbl].[dbo].[User] s 
    LEFT OUTER JOIN [dbl].[dbo].[groupmembership] g ON s.UserrID = g.UserrID 
WHERE g.UserID IS NULL 
    OR (g.GroupID NOT IN (" + groupID + ")  )")

    .SetResultTransformer(Transformers.AliasToBean(typeof(User)));

return (IList<Subscriber>)query.List<User>();

有没有办法可以将其写为 NHibernate 查询?

非常感谢您的帮助,

4

1 回答 1

0
.CreateSQLQuery(
    @"FROM User u left join u.GroupMembership g
    WHERE g.User is null
      OR g.GroupId not in (:groupids)"
.SetParameterList("groupids", groupIds)
.List<User>();

鉴于 GroupMembership 是 user 的属性,而 User 和 GroupId 是 GroupMembership 的属性。(如果GroupId为主键,可以简化)。

于 2012-12-11T10:52:41.103 回答