我有这个覆盖类:
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。
答案 0 :(得分:1)
我已经确认这是一个错误。我从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覆盖不起作用。