流畅的 nhibernate:查询多对多实体,相当于“any”;关键词

发布于 2024-12-05 02:21:50 字数 679 浏览 3 评论 0原文

我在学生和教授(_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 无法识别任何内容来过滤列表。任何相当于什么?

_unitOfWork.Session.QueryOver<Professor>()
   .Where(x => x.Students.Any(i => i.Id.IsIn(childStudentList))).List();

I have a mant-to-many relationship modeled in the database (with a bridge table) between Student and Professor (_students_selected) , in my entites i have modeled it as a many-to-many relationship i.e. a Professor has many Students.

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; }
        }
}

I am unable to query over the professors students, i have tried the following however nhibernate does not recognise Any to filter through the list. Whats the equivalent to any?

_unitOfWork.Session.QueryOver<Professor>()
   .Where(x => x.Students.Any(i => i.Id.IsIn(childStudentList))).List();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

英雄似剑 2024-12-12 02:21:50

这帮助我解决了类似的问题: nhibernate queryover没有急切地加载多对多连接别名

我能够将其减少到:

Role role = null;

session.QueryOver<User>()
    .JoinAlias(u => u.Roles, () => role)
    .Where(() => role.Id == someId);

This helped me with a similar problem: nhibernate queryover not loading eagerly with a many to many joinalias

I was able to reduce it to:

Role role = null;

session.QueryOver<User>()
    .JoinAlias(u => u.Roles, () => role)
    .Where(() => role.Id == someId);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文