1
votes

I've configured Fluent NHibernate to map the entities in my project. None of my entities expose public properties (except their Id), all of their data is stored in private fields.

By using:

public override bool ShouldMap(Member member)
{
     return member.Name == "Id" || (member.IsPrivate && member.IsField);
}

it successfully finds my fields, but then expects my database columns to be called things like _emailAddress.

How can I make it map _emailAddress to a column called EmailAddress? My SessionFactory initialisation looks like:

    Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("AppConnection")))
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<User>(new NHibMappingConfiguration())
    .Conventions.Add(DefaultAccess.CamelCaseField(CamelCasePrefix.Underscore))))
.CurrentSessionContext("web")

.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();

using obviously a default access convention.

Thanks, Matt

1

1 Answers

1
votes

i think you have a couple of options here.
1. you could create your own Convention for naming columns (use the INamingConvention interface. see here).
2. you could create a MappingOverride class for individual classes and define the column name for each one:

mapping.Map(x => x.Name).Column("MyColumnName");