LINQ to NHibernate不能影响孩子们的孩子 [英] LINQ to NHibernate can't get to children's children

查看:88
本文介绍了LINQ to NHibernate不能影响孩子们的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体A,它的B的IList称为Bs,而B有一个C的IList称为Cs.

I have entity A which has an IList of B called Bs and B has an IList of C called Cs.

我要搜索其中至少有5个C的所有A.所以我去写了

I want to search for all A's which have at least 5 C's in them. So I went and wrote

using (var s = this._sessionFactory.OpenSession())
{
    IQueryable<A> q = s.Linq<A>();
    // some code...
    if (range.Min.HasValue)                    
        q = q.Where(a => a.Bs.Sum(b => b.Cs.Count) >= range.Min.Value);
    // some code...
    return q.Select(b=>b).ToArray();
 }

但是,在执行代码(并在range变量中指定Min)时,出现以下异常:

However upon executing the code (and having Min specified in the range variable) I get the following exception :

NHibernate.QueryException:无法解析属性:C of:A

NHibernate.QueryException : could not resolve property: Cs of: A

为什么要在A上寻找B的属性?映射似乎是正确的:

Why does it look for the B's property on A? The mappings seem to be right though :

A上的(流利)映射说:

The (Fluent) mapping on A says :

//...
HasMany(a => a.Bs)
 .Table("Bs")
 .KeyColumn("IdA")
 .Cascade.AllDeleteOrphan()
 .Inverse()
 .Not.LazyLoad();
//...

在B上的映射上说:

//...
HasMany(b => b.Cs)
 .Table("Cs")
 .KeyColumn("IdB")
 .Cascade.AllDeleteOrphan()
 .Inverse()
 .Not.LazyLoad();
References(b => b.A, "IdA")
 .Not.LazyLoad();
//...

最后在C上进行映射:

References(c => c.B, "IdB").Not.LazyLoad();

推荐答案

您无法使用LINQ to NHibernate 2.x

You can't do it with LINQ to NHibernate 2.x

这篇关于LINQ to NHibernate不能影响孩子们的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆