我在学生和教授(_students_selected)之间的数据库(带有桥接表)中建立了一对多关系,在我的网站中,我将其建模为多对多关系,即教授有很多生。
HasManyToMany(x => x.Students)
.Table("_students_selected").ChildKeyColumn("student_key").ParentKeyColumn("professor_key");
public class Professor
{
private IList<Students> _students;
public virtual Student Students
{
get { return _students; }
set { _students = value; }
}
}
我无法查询教授学生,我已经尝试了以下但是nhibernate不承认Any过滤列表。什么相当于什么?
_unitOfWork.Session.QueryOver<Professor>()
.Where(x => x.Students.Any(i => i.Id.IsIn(childStudentList))).List();
答案 0 :(得分:1)
这对我有类似的问题:nhibernate queryover not loading eagerly with a many to many joinalias
我能够将其缩小为:
Role role = null;
session.QueryOver<User>()
.JoinAlias(u => u.Roles, () => role)
.Where(() => role.Id == someId);