【问题标题】:Convert hbm.xml Mappings to Confirmist Code Mapping in Nhibernate在 Nhibernate 中将 hbm.xml 映射转换为 Confirmist 代码映射
【发布时间】:2014-11-12 03:38:05
【问题描述】:

目前我正在将 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 子句和类类型。谁能帮帮我。

【问题讨论】:

    标签: c# nhibernate nhibernate-mapping


    【解决方案1】:

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

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

    【讨论】:

    • 不,没有给我添加 where 子句的选项
    • @MoizKachwala:我不确定你的意思。上面的映射中有一个m.Where 调用....
    猜你喜欢
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 2012-04-09
    • 2013-05-30
    • 2014-04-02
    • 1970-01-01
    相关资源
    最近更新 更多