NaturalId 在自动映射覆盖中不起作用

发布于 2024-11-05 11:57:44 字数 2817 浏览 0 评论 0原文

我有这个覆盖类:

public class UserAutoMappingOverride : IAutoMappingOverride<User>
{
    public void Override(AutoMapping<User> mapping)
    {
        mapping.ReadOnly();

        mapping.Cache.ReadOnly();

        mapping.Table("VIEW_ACTIVE_USERS");

        mapping.Id(x => x.Id, "ID")
            .GeneratedBy
            .Native("SEC_USERS_SEQ");

        mapping.NaturalId()
            .Property(x => x.Username, "ACTIVE_DIRECTORY_LOGIN")
            .ReadOnly();

        mapping.Map(x => x.EmailAddress, "EMAIL_ADDRESS");
        mapping.Map(x => x.FirstName, "FIRST_NAME");
        mapping.Map(x => x.LastName, "LAST_NAME");

        mapping.HasManyToMany<Role>(x => x.Roles)
            .ReadOnly()
            .Inverse()
            .Table("PFS_SEC_USERS_GROUPS_011")
            .ParentKeyColumn("SEC_USER_ID")
            .ChildKeyColumn("SEC_GROUP_ID")
            .Cascade.None()
            .AsSet();
    }
}

它会生成此 XML 映射:

<class xmlns="urn:nhibernate-mapping-2.2" mutable="false" name="iPFSv2.Core.Security.User, iPFSv2.Core, Version=1.9.5.0, Culture=neutral, PublicKeyToken=null" table="VIEW_ACTIVE_USERS">
  <cache usage="read-only" />
  <id name="Id" type="System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="ID" />
    <generator class="native">
      <param name="sequence">SEC_USERS_SEQ</param>
    </generator>
  </id>
  <set cascade="none" inverse="true" name="Roles" table="PFS_SEC_USERS_GROUPS_011" mutable="false">
    <key>
      <column name="SEC_USER_ID" />
    </key>
    <many-to-many class="iPFSv2.Core.Security.Role, iPFSv2.Core, Version=1.9.5.0, Culture=neutral, PublicKeyToken=null">
      <column name="SEC_GROUP_ID" />
    </many-to-many>
  </set>
  <property name="EmailAddress" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="EMAIL_ADDRESS" />
  </property>
  <property name="FirstName" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="FIRST_NAME" />
  </property>
  <property name="LastName" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="LAST_NAME" />
  </property>
  <property name="Username" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="Username" />
  </property>
</class>

如您所见,某些覆盖正在工作,但自然 ID 覆盖却不起作用。我做错了什么还是这是一个错误?查看 DLL 的属性,看起来我使用的是程序集版本 1.2.0.694。

I have this override class:

public class UserAutoMappingOverride : IAutoMappingOverride<User>
{
    public void Override(AutoMapping<User> mapping)
    {
        mapping.ReadOnly();

        mapping.Cache.ReadOnly();

        mapping.Table("VIEW_ACTIVE_USERS");

        mapping.Id(x => x.Id, "ID")
            .GeneratedBy
            .Native("SEC_USERS_SEQ");

        mapping.NaturalId()
            .Property(x => x.Username, "ACTIVE_DIRECTORY_LOGIN")
            .ReadOnly();

        mapping.Map(x => x.EmailAddress, "EMAIL_ADDRESS");
        mapping.Map(x => x.FirstName, "FIRST_NAME");
        mapping.Map(x => x.LastName, "LAST_NAME");

        mapping.HasManyToMany<Role>(x => x.Roles)
            .ReadOnly()
            .Inverse()
            .Table("PFS_SEC_USERS_GROUPS_011")
            .ParentKeyColumn("SEC_USER_ID")
            .ChildKeyColumn("SEC_GROUP_ID")
            .Cascade.None()
            .AsSet();
    }
}

It results in this XML mapping being generated:

<class xmlns="urn:nhibernate-mapping-2.2" mutable="false" name="iPFSv2.Core.Security.User, iPFSv2.Core, Version=1.9.5.0, Culture=neutral, PublicKeyToken=null" table="VIEW_ACTIVE_USERS">
  <cache usage="read-only" />
  <id name="Id" type="System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="ID" />
    <generator class="native">
      <param name="sequence">SEC_USERS_SEQ</param>
    </generator>
  </id>
  <set cascade="none" inverse="true" name="Roles" table="PFS_SEC_USERS_GROUPS_011" mutable="false">
    <key>
      <column name="SEC_USER_ID" />
    </key>
    <many-to-many class="iPFSv2.Core.Security.Role, iPFSv2.Core, Version=1.9.5.0, Culture=neutral, PublicKeyToken=null">
      <column name="SEC_GROUP_ID" />
    </many-to-many>
  </set>
  <property name="EmailAddress" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="EMAIL_ADDRESS" />
  </property>
  <property name="FirstName" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="FIRST_NAME" />
  </property>
  <property name="LastName" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="LAST_NAME" />
  </property>
  <property name="Username" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="Username" />
  </property>
</class>

As you can see, some of the overrides are working, but the natural ID override is not. Am I doing something wrong or is this a bug? Looking at the properties for my DLL it looks like I am using assembly version 1.2.0.694.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皓月长歌 2024-11-12 11:57:44

我已经确认这是一个错误。我从 github 下载了最新的 master 分支,并将以下测试添加到 AutoPersistenceModelTests.Overrides.cs 文件中:

    [Test]
    public void NaturalIdOverrideShouldOverrideExistingProperty()
    {
        var autoMapper = AutoMap.AssemblyOf<ExampleClass>()
            .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures")
            .Override<ExampleClass>(c => c.NaturalId().Property(x => x.LineOne, "test"));

        var a = new AutoMappingTester<ExampleClass>(autoMapper);

        new AutoMappingTester<ExampleClass>(autoMapper)
            .Element("//natural-id/property[@name='LineOne']")
            .Exists()
            .HasThisManyChildNodes(1)
            .Element("//natural-id/property[@name='LineOne']/column").HasAttribute("name", "test");
    }

测试失败。自然 ID 覆盖不起作用。

I've confirmed that this is a bug. I downloaded the latest master branch from github and added the following test to the AutoPersistenceModelTests.Overrides.cs file:

    [Test]
    public void NaturalIdOverrideShouldOverrideExistingProperty()
    {
        var autoMapper = AutoMap.AssemblyOf<ExampleClass>()
            .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures")
            .Override<ExampleClass>(c => c.NaturalId().Property(x => x.LineOne, "test"));

        var a = new AutoMappingTester<ExampleClass>(autoMapper);

        new AutoMappingTester<ExampleClass>(autoMapper)
            .Element("//natural-id/property[@name='LineOne']")
            .Exists()
            .HasThisManyChildNodes(1)
            .Element("//natural-id/property[@name='LineOne']/column").HasAttribute("name", "test");
    }

The test fails. Natural ID override is not working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文