Note that there are some explanatory texts on larger screens.

plurals
  1. POFluentNHibernate - Getting the entity name when mapping. Current method being made obsolete
    text
    copied!<p>I am currently automatically naming my tables in fluent NHibernate by using AutoMappingOverride's and setting the name of the table to the pluralised name of the entity like so. </p> <pre><code>public class PersonMappingOverride : IAutoMappingOverride&lt;Person&gt; { public void Override(AutoMapping&lt;Person&gt; mapping) { mapping.Table(mapping.EntityType.Name.Pluralize()); mapping.Id(x =&gt; x.PersonId).Column("PersonId").GeneratedBy.Increment(); mapping.Map(x =&gt; x.Name).CustomSqlType("nvarchar(200)"); } } public static string Pluralize(this string input) { return System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new CultureInfo("en-US")).Pluralize(input); } </code></pre> <p>I am getting the following error.</p> <p>'FluentNHibernate.Mapping.ClasslikeMapBase.EntityType' is obsolete: 'Do not call this method. Implementation detail mistakenly made public. Will be made private in next version.'</p> <p>Does anyone know the correct way of getting the entity name? I've done a fair bit of Googling and have only found examples of people using this obsolete method to achieve what I need. </p> <p>Cheers</p> <h2>Steve</h2> <p>Thanks for all the great help guys. Using conventions is way more elegant for my use case than the overrides anyway. </p> <pre><code>var sqlConfig = MsSqlConfiguration.MsSql2005.ConnectionString(ConnectionString); var config = Fluently.Configure().Database(sqlConfig); config.Mappings(c =&gt; c.AutoMappings.Add(AutoMap.AssemblyOf&lt;User&gt;(new IJAutomappingConfiguration()).Conventions.AddFromAssemblyOf&lt;TableNamingConvention&gt;())); public class TableNamingConvention : IClassConvention { public void Apply(IClassInstance instance) { instance.Table(instance.EntityType.Name.Pluralize()); } } </code></pre> <p>Here is the full code to get this working. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload