NHibernate:列名不明确时,一对多关系中的where子句不起作用 [英] NHibernate: Where clause on one-to-many relationships doesn't work when column name is ambiguous

查看:72
本文介绍了NHibernate:列名不明确时,一对多关系中的where子句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以为集合映射指定一个任意的SQL where子句.例如:

It is possible to specify an arbitrary SQL where clause for collection mappings. For example:

<map name="myEntity" where="foo = 1" />

但是,如果由于某种原因列名不明确,则sql会失败.例如,如果您尝试使用联接,则可能发生这种情况.

However if the column name is ambiguous for some reason, the sql fails. For example, this can occur if you are trying to use joins for example.

鉴于表别名是自动生成的,因此您不能限定列名.这使该功能看起来很愚蠢.有人知道有没有解决的办法?

Given that the table aliases are automatically generated, you can't qualify the column name. This makes the feature seem rather silly. Does anyone know if there is a work around?

推荐答案

NHibernate应该为您所引用的属性找出正确的别名. foo是项目实体类型(地图集合中的项目类型)的映射属性吗?

NHibernate should figure out the correct alias for the property you are referencing. Is foo a mapped property of the item entity type (the item type that is in the map collection) ?

例如,这可行:

<class name="Category" table="Category">
  <id name="Id">
    <generator class="guid.comb" />
  </id>

  <property name="Name" not-null="true" length="255" />

  <bag name="ProductList" table="Product" cascade="none" where="Name like '%test%'" fetch="join">
    <key column="CategoryId" />
    <one-to-many class="Product" />
  </bag>

</class>

类别和产品类上都有一个名为名称"的属性,但是在这种情况下,nhibernate将使用产品类上定义的on.

There is a property on both Category and the Product class named "Name" but nhibernate will in this case use the on defined on the Product class.

这篇关于NHibernate:列名不明确时,一对多关系中的where子句不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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