NHibernate(+ FluentNhibernate):连接两个独立的表 [英] NHibernate (+ FluentNhibernate) : Join two detached tables
问题描述
我无法在具有相同属性的两个实体上创建联接时遇到问题,但是它们没有映射在一起.
'tI encounter problems to create a join on two entities with a common property but they are not map together.
假设您有一个实体Article,其中包含属性FamilyCode和具有属性Code和Label的实体Family.
Say you have an entity Article which contains a property FamilyCode and an entity Family with properties Code and Label.
在我的映射中,Article没有引用Family,并且我不想更改它(以保持与其他内部和旧方法的兼容性).
In my mappings, Article doesn't reference Family and i don't want to change that (to keep compatibility with others internal and legacy methods).
因此,我无法在Nhibernate中翻译以下查询:
So, i can't translate the below query in Nhibernate :
SELECT f.Code, f.Label
FROM Article a
INNER JOIN Family f ON a.FamilyCode = f.Code
WHERE f.Label LIKE 'p%'
我无法使用JoinQuery,因为我无法注入QueryOver,并且如果使用WithSubquery有可能,我也不知道.
I can't use JoinQuery because i can't inject a QueryOver and i don't konw if it's possible by using WithSubquery.
我尝试使用Future QueryOver和QueryOver,然后在内存中执行Join(每个.List()之后),但是我的Article行太多,因此需要很长时间.
I tried to Future QueryOver and QueryOver and then perform a Join in memory (after .List() each) but i have too much rows for Article so it takes long time.
您有想法吗?
谢谢.
推荐答案
我们可以使用HQL-但仅 HQL.
We can use HQL - but only HQL.
- 14.2. from子句 (小引用和摘录)
可能会出现多个类,从而导致笛卡尔积或交叉"联接.
Multiple classes may appear, resulting in a cartesian product or "cross" join.
from Formula, Parameter
from Formula as form, Parameter as param
这就是HQL的方式
SELECT f.Code, f.Label
FROM Article a,
Family f
WHERE a.FamilyCode = f.Code
AND f.Label LIKE 'p%'
还要检查此 9.3.2. IQuery界面,也可能是 Q& A
Check also this 9.3.2. The IQuery interface and maybe this Q & A
这篇关于NHibernate(+ FluentNhibernate):连接两个独立的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!