我得到一个"重复协会路径"访问时,在NHibernate的标准误差同一个表两次 [英] I am getting a "duplicate association path" error in the NHibernate Criteria when accessing the same table twice

查看:206
本文介绍了我得到一个"重复协会路径"访问时,在NHibernate的标准误差同一个表两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有个createCriteria,增加了一个连接到同一个表两次不同的别名:

I have a CreateCriteria that adds a join to the same table twice with different aliases:

aCriteria.CreateCriteria("Color", "co").Add(Expression.In("co.ColorId", bikush.Color.Select(x => x.ColorId).ToList()));

aCriteria.CreateCriteria("Color","fco").Add(Expression.In("fco.ColorId",bikush.FCColor.Select(x => x.ColorId).ToList()));

我收到了错误重复协会路径

I'm getting the error "duplicate association path"

下面是我想要生成SQL语句:

Here is the SQL I want to generate:

SELECT b.BikushId,C。[名] AS PlainColor,FC。[名] AS FancyColor从Bikush b INNER JOIN BikushInColor CLT ON clt.BikushId = b.BikushId INNER JOIN颜色C对CLT .ColorId = c.ColorId INNER JOIN BikushInFCColor附设开b.BikushId = bifc.BikushId INNER JOIN颜色FC的bifc.ColorId = fc.ColorId

反正是有解决这个使用NHibernate的CriteriaApi?

Is there anyway around this using the CriteriaApi of Nhibernate?

感谢

推荐答案

别名是属性,而不是表名。尝试:

The alias is for the property, not the table name. Try:

aCriteria.CreateCriteria("Color", "co").Add(Expression.In("co.ColorId", bikush.Color.Select(x => x.ColorId).ToList()));  
aCriteria.CreateCriteria("FancyColor","fco").Add(Expression.In("fco.ColorId",bikush.FCColor.Select(x => x.ColorId).ToList()));

这篇关于我得到一个"重复协会路径"访问时,在NHibernate的标准误差同一个表两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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