NaturalId Not Working in Auto Mapping Override
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, mscorli开发者_如何学Cb, 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.
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.
精彩评论