Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After not getting anywhere I decided to step through the Fluent nHibernate code to see what was happening. I then located how the 'DefaultAutomappingConfiguration' was setup, and created my own version:</p> <pre><code>public class MyAutomappingStoreConfiguration : DefaultAutomappingConfiguration { public override IEnumerable&lt;IAutomappingStep&gt; GetMappingSteps(AutoMapper mapper, IConventionFinder conventionFinder) { return new IAutomappingStep[] { new IdentityStep(this), new MyChangeCheckVersionStep(this), new ComponentStep(this, mapper), new PropertyStep(conventionFinder, this), new HasManyToManyStep(this), new ReferenceStep(this), new HasManyStep(this) }; } } </code></pre> <p>Note the <strong>MyChangeCheckVersionStep</strong> which is what is different. I then implemented a <strong>VersionStep</strong> class that added <strong>ChangeCheck</strong> to the list of column names that are assumed to be Version columns:</p> <pre><code>public class MyChangeCheckVersionStep: IAutomappingStep { private static readonly IList&lt;string&gt; validNames = new List&lt;string&gt; { "version", "timestamp", "changecheck" }; private static readonly IList&lt;Type&gt; validTypes = new List&lt;Type&gt; { typeof(int), typeof(long), typeof(TimeSpan), typeof(byte[]) }; private readonly IAutomappingStep defaultVersionStep; public MyChangeCheckVersionStep(IAutomappingConfiguration cfg) { this.defaultVersionStep = new VersionStep(cfg); } public bool ShouldMap(Member member) { return validNames.Contains(member.Name.ToLowerInvariant()) &amp;&amp; validTypes.Contains(member.PropertyType); } public void Map(ClassMappingBase classMap, Member member) { defaultVersionStep.Map(classMap, member); } } </code></pre> <p>The class basically calls the defualt <strong>VersionStep</strong> implementation for everything but <strong>ShouldMap</strong>.</p> <p>Now I no longer need to create overrides for each entity to get the Version working. Note as well, that I still use the <strong>ChangeCheckVersionConvention</strong> - it is the override on every entity class I no longer need.</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