在Hhibernate中将hbm.xml映射转换为Confirmist代码映射

时间:2014-11-11 06:33:52

标签: c# nhibernate nhibernate-mapping

目前我正在将hbm.xml文件转换为代码映射(Confirmist)。我能够转换所有内容,但我不知道如何转换manyToMany属性中的where子句。

<set inverse="true" name="Skills" table="UserPrivileges" mutable="true">
            <key>
                <column name="UserID" />
            </key>
            <many-to-many class="School.Campaign.Domain.Skill, School.Campaign.Domain" where="PrivilegeType = 'Skill'">
                <column name="PrivilegeID" />
            </many-to-many>
        </set>

这时我转换成这样:

Set(x => x.Skills, m =>
                {
                    m.Schema("dbo");
                    m.Table("UserPrivileges");
                    m.Key(k => k.Column("UserID"));
                    m.Cascade(Cascade.None);
                }, col => col.ManyToMany(m =>
                {
                    m.Columns(x => x.Name("PrivilegeID"));
                })
                );

但是这不起作用,因为缺少where子句和类类型。任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

您应该可以在.Where映射选项中调用.ManyToMany

Set(x => x.Skills, m =>
{
    m.Schema("dbo");
    m.Table("UserPrivileges");
    m.Key(k => k.Column("UserID"));
    m.Cascade(Cascade.None);
}, col => col.ManyToMany(m =>
{
    m.Columns(x => x.Name("PrivilegeID"));
    m.Where("PrivilegeType = 'Skill'"); // <-----
}));