This question has already been asked , but there was no decent answer.
Is there a property name convention for free nhibernate, so instead of searching for Id
it searches for ProductId
?
PrimaryKeyConvention
applies to column names in the database, not property names.
Consider this scenario:
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(); }
leads to:
FluentNHibernate.Visitors.ValidationException: The entity "Product" does not have an identifier. Use the Id method to match your ID. For example: Id (x => x.Id).
In what convention can I add / override to freely speak nhibernate to search for "EntityName" + "Id" in property names? I looked at this talk page, but havent found one that will override.
source share