如何在多对多关联的情况下使用Future查询Nhibernate

时间:2015-07-10 20:17:39

标签: c# .net linq hibernate nhibernate

我和学生之间有很多很多关系。

public class Student 
{
    public virtual Id {get; set;}
    public virtual Name {get; set;}
    public virtual IList<Course> Courses {get; set;}
}

public class Course
{
    public virtual Id {get; set;}
    public virtual Name {get; set;}
    public virtual IList<Student> Students {get; set;}
}

这些实体具有相应的表,包括CourseToStudent的多对多表。

我想使用Nhibernate future编写最优化的查询来获取课程或学生。

我知道我可以在一对多中使用未来,但我们如何使用future来编写多对多的查询。

例如,对于一些一对多的查询学期课程。 1个学期可以有很多课程,但1个课程只能属于一个学期。

所以我可以将未来的查询写成

Semester= _repository.Future<Entity.Semester>(_repository.Query<Entity.Semester>().where(x=>x.Id = semesterId));

Course= _repository.Future<Entity.Course>(_repository.Query<Entity.Course>().where(x=>x.Semester.Id = semesterId));

但我很困惑如何在多对多的情况下使用未来。谁能解释我是否应该在这里使用未来。

0 个答案:

没有答案
相关问题