NHibernate QueryOver distinct -
i have scenario:
class user { id, username } class userrelationship { user groupuser, user memberuser } , query var query = queryover.of<userrelationship>() .joinqueryover(x=>x.memberuser) .where(x=>x.username == "testuser");
now want return list distinct user, cannot
transformusing(transformers.distinctrootentity)
because give me userrelationship.
i need this:
select distinct user.id userrelationship relationship inner join user user on user.id = relationship.memberuser_id
please thanks
given classes:
public class user { public virtual int id {get; set;} public virtual string username {get; set;} } public class userrelationship { public virtual int id {get; set;} public virtual user groupuser {get; set;} public virtual user memberuser {get; set;} }
and fluent mappings of:
public class usermap : classmap<user> { public usermap() { id(x=>x.id).generatedby.native(); map(x=>x.username); } } public class userrelationshipmap : classmap<userrelationship> { public userrelationshipmap(){ id(x=>x.id).generatedby.native(); references(x=>x.groupuser); references(x=>x.memberuser); } }
you want retrieve list of distinct "user" based on "memberuser" userrelationship class.
var distinctmemberusers = queryover.of<userrelationship>() .select(x => x.memberuser.id); var users = queryover.of<user>() .withsubquery.whereproperty(x=>x.id).in(distinctmemberusers)
this should use in clause in sql give distinct list of user.
Comments
Post a Comment