发现此问题: 即解决方案。
标识
的automapper被坚持己见,它期望被设计为以特定的方式你的类;如果它们不是,那么它将无法在没有一点帮助的情况下自动映射它们。 automapper期望你的身份被命名为Id,如果他们不是,它不会找到它们。
您可以通过在自动映射配置中重写IsId方法来修改自动映射器发现标识的方式。这个方法将会被你的实体中已经被ShouldMap(成员)标准接受的所有成员调用;无论哪个成员您返回true都会被映射为身份。
public override bool IsId(Member member)
{
return member.Name == member.DeclaringType.Name + "Id";
}
该示例将匹配以其实体命名的任何id,例如CustomerId。
,并调用它:
return Fluently.Configure()
.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey("database"))
.ShowSql()
.ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"))
.Mappings(x => x.FluentMappings
.AddFromAssembly(
Assembly.GetExecutingAssembly())
.Conventions.AddFromAssemblyOf<Location.IdConvention>())
.BuildSessionFactory();
并且设置了ID CONVENCION后
public class IdConvention : IIdConvention
{
public void Apply(IIdentityInstance identityInstance)
{
identityInstance.Column(identityInstance.EntityType.Name + "Id");
}
}