나는이 코드를 사용하여 모든 가능한 그룹을 가져옵니다. 내가 가진 문제는 아이들도 사용할 수 없게되지만 유창한 nhibernate가 모두 아이들이 활성화 된 그룹 만 가져올 수는 없다는 것입니다. 나는 이것이 가능하다고 생각하지만 어떻게?NHibernate - 하위 속성을 기반으로 결과를 필터링
public class Group {
public bool IsDisabled { get; set; }
public string Description { get; set; }
public ICollection<ChildType> Children { get; protected set; }
}
public class ChildType {
public bool IsDisabled { get; set; }
public string Description { get; set; }
}
public IList<Group> Search(string searchString) {
IQueryOver<Group> query = Session.QueryOver<Group>()
.WhereRestrictionOn(x => x.Description).IsInsensitiveLike(searchString, MatchMode.Start)
.Where(x => !x.IsDisabled)
.OrderBy(x => x.Description).Asc
.Fetch(group => group.Children).Eager;
return query
.Cacheable()
.List();
}
편집 : 아이들과 그룹 사이의 M-관계 :는 N있다. 당신이 원하는 일을해야
public class Group {
public long Id { get; set; }
public bool IsDisabled { get; set; }
public string Description { get; set; }
public ICollection<ChildType> Children { get; protected set; }
}
public class ChildType {
public long Id { get; set; }
public bool IsDisabled { get; set; }
public string Description { get; set; }
public ICollection<Group> Groups { get; protected set; }
}
public IList<Group> Search(string searchString) {
ChildType child = null;
Group group = null;
Group joinedGroup = null;
var notDisabled = Session.QueryOver.Of<ExaminationType>()
.Where(x => x.IsDisabled)
.JoinAlias(x => x.Groups,() => joinedGroup)
.Where(x => joinedGroup == group)
.Select(x => x.Id);
IQueryOver<Group> query = Session.QueryOver<Group>()
.WhereRestrictionOn(x => x.Description).IsInsensitiveLike(searchString, MatchMode.Start)
.JoinAlias(x => x.ExaminationTypes,() => child)
.WithSubquery.WhereNotExists(notDisabled)
.OrderBy(x => x.Description).Asc;
return query
.Cacheable()
.List();
}
하위 그룹과 하위 그룹 사이에 N : M- 관계가 있습니다. 하위 쿼리를 약간 짜증나게 만들지 만 해결한다면이 방법을 사용합니다. 감사합니다. –
하위 쿼리의 경우 투영을 수행하는 데 '선택'만 사용해야합니다. – Vadim