Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate - Setting CutomType IIdConvention
    text
    copied!<p>I have the following IIdConvention for a FluentNHibernate automapping. I want all of my id properties to use a custom type that is represented by a string property but the CustomType is never applied to my mappings. </p> <pre><code>public class PrimaryKeyHasTableName : FluentNHibernate.Conventions.IIdConvention { public void Apply(FluentNHibernate.Conventions.Instances.IIdentityInstance instance) { instance.Column(instance.EntityType.Name + "Id"); instance.CustomType&lt;CustomIdType&gt;(); } } </code></pre> <p>When I looked into the FluentNHibernate source it appears that the Type for the id property has already been set so it is not being set by my convention.</p> <p>If I use a ClassMap to map the class manually I have not problem setting the CustomType for the Identity property.</p> <pre><code> Id(x =&gt; x.Id) .Column("UserId") .CustomType&lt;OnFileIdType&gt;(); </code></pre> <p>Does anybody know how I can successfully set the custom id property using a convention? </p> <p>Or get my convention to run earlier in the mapping process so that the Type isn't already set by the time my code runs.</p> <p>Also, here's my configuration code:</p> <pre><code>Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connString)) .Mappings(m =&gt; { m.FluentMappings.AddFromAssemblyOf&lt;BaseEntity&gt;(); m.AutoMappings.Add(AutoMap.AssemblyOf&lt;BaseEntity&gt;() .Where(t =&gt; t.Namespace.EndsWith("Models.Domain")) .Conventions.AddFromAssemblyOf&lt;BaseEntity&gt;() .UseOverridesFromAssemblyOf&lt;BaseEntity&gt;() ); }) .ExposeConfiguration(CreateSchema) .BuildSessionFactory(); </code></pre> <p>Thanks.</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