NH3.2使用' where'代码进行映射条款 [英] NH3.2 Mapping By Code using 'where' clause

查看:107
本文介绍了NH3.2使用' where'代码进行映射条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用NH3.2中的MappingByCode与'where'子句定义多对多关系,但我不知道该怎么做.

I've tried to define many-to-many relation with 'where' clause using MappingByCode from NH3.2, but I don't know how can I do it.

对于FluentNHibernate,我可以使用ChildWhere()方法:

With FluentNHibernate I can use the ChildWhere() method:

 public class ProcedureMap : ClassMap<Procedure>
 {
        public ProcedureMap()
        {
            this.HasManyToMany(a => a.FormTemplates).ChildWhere("IsDeleted = 0").AsSet();
        }
 }

此代码将生成下一个HBM:

This code will generate next HBM:

 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class xmlns="urn:nhibernate-mapping-2.2" name="Procedure" table="Procedure">
    <set name="FormTemplates" table="ProceduresToFormTemplates">
      <key foreign-key="FK_Procedures_FormTemplates">
        <column name="ProcedureId" />
      </key>
      <many-to-many class="FormTemplate" where="IsDeleted = 0">
        <column name="FormTemplateId" />
      </many-to-many>
    </set>
  </class>
 </hibernate-mapping>

如何使用NH3.2中的MappingByCode获得相同的映射?

How can I get same mapping using MappingByCode from NH3.2?

推荐答案

您将在多对多映射中使用filter方法.

You would use the filter method on the many to many mapping.

this.Bag(
   x => x.Procedure,
   m =>
     {
         m.Table("Procedure");
         m.Key(k => k.Column("ProcedureId"));
         m.Filter("NoDeleted", mapper => mapper.Condition("IsDeleted = 0"));
     },
   x => x.ManyToMany(
           map =>
                {
                    map.Column("FormTemplateId");
                }));

这篇关于NH3.2使用&amp;#39; where&amp;#39;代码进行映射条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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