简体   繁体   中英

NHibernate Query using QueryOver HQL

I am writing the follow as an NHibernate Query but cannot find a solution using QueryOver as 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>();

Is there any way possible that this can be written as an NHibernate query?

Many thanks for your help,

.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>();

Given that GroupMembership is a property of user and User and GroupId are properties of the GroupMembership. (If GroupId is the primary key, it can be simplified).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM