Nhibernate NH3.2使用'的代码映射;其中';条款
我曾尝试使用Nhibernate NH3.2使用'的代码映射;其中';条款,nhibernate,fluent-nhibernate,nhibernate-mapping,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,我曾尝试使用NH3.2中的MappingByCode来定义与“where”子句的多对多关系,但我不知道如何才能做到这一点 使用FluentNHibernate我可以使用ChildWhere()方法: public class ProcedureMap : ClassMap<Procedure> { public ProcedureMap() { this.HasManyToMany(a => a.FormTemplat
NH3.2
中的MappingByCode
来定义与“where”子句的多对多关系,但我不知道如何才能做到这一点
使用FluentNHibernate
我可以使用ChildWhere()
方法:
public class ProcedureMap : ClassMap<Procedure>
{
public ProcedureMap()
{
this.HasManyToMany(a => a.FormTemplates).ChildWhere("IsDeleted = 0").AsSet();
}
}
公共类过程映射:类映射
{
公共程序图()
{
this.HasManyToMany(a=>a.FormTemplates).ChildWhere(“IsDeleted=0”).AsSet();
}
}
此代码将生成下一个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
获得相同的映射?您可以在多对多映射上使用过滤器方法
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");
}));