views:

427

answers:

2

Hello,

according to this Post it is possible to change the naming convention from "[TableName]_id" to "[TableName]ID". However when I saw the code, I wasn't able to do it with my rather new (about 6 weeks old) version of Fluent NHibernate.

Original code:

var cfg = new Configuration().Configure();
var persistenceModel = new PersistenceModel();
persistenceModel.addMappingsFromAssembly(Assembly.Load("Examinetics.NHibernate.Data"));
persistenceModel.Conventions.GetForeignKeyNameOfParent = type => type.Name + "ID";
persistenceModel.Configure(cfg);
factory = cfg.BuildSessionFactory();

I came up with this:

PersistenceModel model = new PersistenceModel();
model.AddMappingsFromAssembly(assemblyType.Assembly);
model.ConventionFinder.Add(
    ConventionBuilder.Reference.Always(part
        => part.ColumnName(part.EntityType.Name + part.Property.Name)));

configuration.ExposeConfiguration(model.Configure);
return configuration.BuildConfiguration();

but this gives me the original Table, because EntityType is not the referenced Entity and I see no property to get the "parent" entity.

How can I do this?

A: 

I advise you to read the Fluent NHibernate Wiki, it's a much more up-to-date source of information than random blogs. Particularly there's a Conventions page.

James Gregory
This is really not very helpful. I had checked the wiki first and I was not able to find any useful information, because they don't mention my problem at all.
Icey
+4  A: 

Check post titled: Fluent NHibernate conventions – examples It contains a list of example conventions and one of them matches what you need.

Marcin Obel