NH3.2. Code matching using the where clause

I tried to define a many-to-many relationship with the where MappingByCode using MappingByCode 's NH3.2 , but I don't know how to do this.

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 the following 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 the same mapping using MappingByCode from NH3.2 ?

+4
source share
1 answer

You must use the filter method to display many, many.

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

Source: https://habr.com/ru/post/1389096/


All Articles