I have a Document class which has a User Property which is the User who owns the document, but also I have a User List. Users which have access to the document. I am trying to create a query which will return documents which either I own or I have access to.
IList<Document> results = UnitOfWork.CurrentSession.CreateCriteria(typeof(Document))
.CreateCriteria("Owner")
.CreateCriteria("UserList")
.Add(nh.Criterion.Restrictions.IdEq(obj.Id))
.SetFirstResult(pageSize * page)
.SetMaxResults(pageSize)
.List<Document>();
This above is what I have tried so far but to no avail. The structure of the Document class, shortened is:
public class Document : DomainObject<Document>{
public Document(){
UserList = new List<User>();
}
public virtual User Owner{get;set;}
public virtual IList<User> UserList{get;set;}
}
I appreciate any guidance on this!!
Cheeers,
Andrew
EXAMPLE SQL I AM LOOKING FOR
declare @UserID uniqueidentifier
set @UserID = '37f7a55f-84c9-461b-a5b2-b412fe96932b'
select * from [Document] s
where s.UserID = @UserID
or exists(select * from DocumentUser su where su.userid = @UserID)