NaturalId 在自动映射覆盖中不起作用
我有这个覆盖类:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经确认这是一个错误。我从 github 下载了最新的 master 分支,并将以下测试添加到 AutoPersistenceModelTests.Overrides.cs 文件中:
测试失败。自然 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:
The test fails. Natural ID override is not working.