【问题标题】:Convert XML mappings to Code Mapping for ISET of ManyToMany将 XML 映射转换为 ManyToMany 的 ISET 的代码映射
【发布时间】:2015-03-05 15:02:10
【问题描述】:

我目前正在做一个项目,我需要将 xml 映射转换为代码映射。

我有一个带有多对多以及 where 子句的 ISET 集合。我已经完成了代码映射,但是将 where 子句放在代码映射中的什么位置?

<set inverse="true" name="SystemRoles" table="UserPriv" mutable="true">
    <cache usage="read-write" />
    <key>
        <column name="UserID" />
    </key>
    <many-to-many
       class="SampleProject.Domain.SystemRole, SampleProject.Domain"
       where="PrivilegeType = 'SystemRole'">
        <column name="PrivilegeID" />
    </many-to-many>
</set>

还有我的代码映射:

Set(x => x.SystemRoles, m =>
    {
        m.Schema("dbo");
        m.Table("UserPriv");
        m.Inverse(true);
        m.Key(k => k.Column("UserId"));
        m.Cascade(Cascade.None);
    }, col => col.ManyToMany(p =>
    {
        p.Column(x => x.Name("PrivilegeId"));
    })
    );

我应该放在哪里:where="PrivilegeType = 'SystemRole'"

【问题讨论】:

    标签: nhibernate nhibernate-mapping hibernate-mapping nhibernate-mapping-by-code


    【解决方案1】:

    where 应该属于 many-to-many,就像在 xml 映射中一样

    Set(x => x.SystemRoles, m =>
        {
            // set mapping
        }, 
        col => col.ManyToMany(p =>
        {
            // mapping of the many-to-many
            p.Column(x => x.Name("PrivilegeId"));
            p.Where("PrivilegeType = 'SystemRole'");
        })
        );
    

    但不能完全确定,如果代码映射中已经支持所有功能...

    Adam Bar 的更多“文档”http://notherdev.blogspot.com/2012/01/mapping-by-code-onetomany-and-other.html

    EXTEND,查看https://github.com/nhibernate/nhibernate-core/blob/master/releasenotes.txt

    对于Build 4.0.0.Alpha1

    • [NH-2997] - 缺少具有多对多关系的 Where() 子句(描述中的解决方案)

    【讨论】:

    • 你能看看这个解决方案是否有效吗? stackoverflow.com/questions/8714307/…
    • 有一个 where ..我刚刚测试过...您使用的是哪个版本的 NHibernate?你有最新的吗?
    • 您测试的是哪个版本?我在 v 3.3 中
    • 有实际注释:Build 4.0.0.Alpha1 .... * [NH-2997] - 缺少具有多对多关系的 Where() 子句(描述中的解决方案)* 所以你应该升级..一切都解决了! ;) 那很棒不是吗?
    • 是的,我们正计划升级。但主要变化是我们使用的是 Iesi 集合,但 Nh 4 使用的是内置的,所以有很多重大变化
    猜你喜欢
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 2018-07-23
    • 1970-01-01
    相关资源
    最近更新 更多