0
此问题已被asked already,但没有像样的答案。流利nhibernate PrimaryKeyConvention为属性名称
是否有属性名约定功能NHibernate以便不用找Id
它看起来ProductId
?
PrimaryKeyConvention
适用于数据库中的列名称,而不是属性名称。
考虑这种情况:
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
}
public class AutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Type type)
{
bool shouldMap = type.In(typeof(Product));
return shouldMap;
}
}
public void TestFluentNHibernate()
{
var configuration = Fluently.Configure().
Database(MsSqlConfiguration.MsSql2008.ConnectionString("database=asd;server=.\\sqlexpress;trusted_connection=true;"))
.Mappings(m =>
{
IAutomappingConfiguration cfg = new AutomappingConfiguration();
m.AutoMappings.Add(AutoMap.AssemblyOf<Product>(cfg).Conventions.AddFromAssemblyOf<PrimaryKeyConvention>());
});
var factory = configuration.BuildSessionFactory();
}
结果:
FluentNHibernate.Visitors.ValidationException:实体 '产品' 不具有标识映射。使用Id方法来映射您的身份属性。例如:Id(x => x.Id)。
什么约定可以添加/重写告诉流利的nhibernate在属性名称中查找'EntityName'+“Id”?我看过this会议页面,但没有找到一个重写。