我有以下 FNH 映射:
public class ItemMap : ClassMap<Item>
{
public ItemMap ()
{
this.HasManyToMany(a => a.ChildItems).ChildWhere("IsDeleted = 0").AsSet();
}
}
结果 hbm 文件为:
<hibernate-mapping>
<class name="Item" table="Item">
<set name="ChildItems" table="ItemsToChildItems">
...
<many-to-many class="ChildItem" where="IsDeleted = 0">
<column name="ChildItemId" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
我想使用NHibernate 3.2 的“通过代码功能进行性感映射:-) / 循规蹈矩的方法”来实现相同的映射
注意: 以下方法不起作用:
public class ItemMap : ClassMapping<Item>
{
public ItemMap()
{
this.Set(x => x.ChildItems
, map =>
{
map.Where("IsDeleted = 0");
}
, action => action.ManyToMany());
}
}
因为: 它遵循 FNH 映射:
public class ItemMap : ClassMap<Item>
{
public ItemMap ()
{
this.HasManyToMany(a => a.ChildItems).Where("IsDeleted = 0").AsSet();
}
}
.Where("IsDeleted = 0") 和 .ChildWhere("IsDeleted = 0") 不一样。
HBM 差异:
结果 hbm 文件使用.ChildWhere("IsDeleted = 0")
的是:
<hibernate-mapping>
<class name="Item" table="Item">
<set name="ChildItems" table="ItemsToChildItems">
...
<many-to-many class="ChildItem" where="IsDeleted = 0">
<column name="ChildItemId" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
结果 hbm 文件使用.Where("IsDeleted = 0")
的是:
<hibernate-mapping>
<class name="Item" table="Item">
<set name="ChildItems" table="ItemsToChildItems" where="IsDeleted = 0">
...
<many-to-many class="ChildItem">
<column name="ChildItemId" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
谁有类似的问题或可以提供解决方案?需要帮忙。