NH3.2使用'where'子句按代码映射 [英] NH3.2 Mapping By Code using 'where' clause
本文介绍了NH3.2使用'where'子句按代码映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从 NH3.2 $ c $使用
方法: MappingByCode
定义与'where'子句的多对多关系但是我不知道该怎么做。
$ b $使用 FluentNHibernate
我可以使用< code $> ChildWhere()
public class ProcedureMap:ClassMap< Procedure>
{
public ProcedureMap()
{
this.HasManyToMany(a => a.FormTemplates).ChildWhere(IsDeleted = 0)。
这段代码将会生成下一个HBM:
< hibernate-mapping xmlns =urn:nhibernate-mapping-2.2>
< class xmlns =urn:nhibernate-mapping-2.2name =Proceduretable =Procedure>
< column name =ProcedureId/>
< / key>
< column name =FormTemplateId/>
>
< / set>
< / class>
< / hibernate-mapping>
如何使用 MappingByCode
从 NH3.2
?
解决方案
this.Bag(
x => x.Procedure,
m = >
{
m.Table(Procedure);
m.Key(k => k.Column(ProcedureId));
m.Filter mapper.Condition(IsDeleted = 0));
},
x => x.ManyToMany(
map =>
{
map.Column(FormTemplateId);
}));
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
?
解决方案 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使用'where'子句按代码映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文