NH3.2 Mapping By Code using 'where' clause

寵の児 提交于 2019-12-10 16:39:34

问题


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.

With FluentNHibernate I can use the ChildWhere() method:

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

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>

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


回答1:


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");
                }));


来源:https://stackoverflow.com/questions/8714307/nh3-2-mapping-by-code-using-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!