Automapping read only non-ID properties

Andreas Folkesson's Avatar

Andreas Folkesson

18 Jun, 2010 08:53 AM via web

Hi,

Thanks for a great tool.

I'm in the process of switching from classic hbm-mapping to automapping.

I have an issue with read only properties, that aren't id:s. It seems the GetAccessStrategyForReadOnlyProperty method is not called for regular properties.

I have some properties that I absolutely want to keep read only, how can this be achieved with automapping?

  1. 2 Posted by Andreas Folkesson on 18 Jun, 2010 09:16 AM

    Andreas Folkesson's Avatar

    I solved this by adding a convention:

    public class ReadOnlyConvention : IPropertyConvention

    {
        public void Apply(IPropertyInstance instance)
        {
            if (instance.Property.IsProperty && !instance.Property.CanWrite)
                instance.Access.CamelCaseField(FluentNHibernate.Conventions.Inspections.CamelCasePrefix.Underscore);
        }
    }
    

    But I would be much happier if the PropertyStep.GetPropertyMapping method called the GetAccessStrategyForReadOnlyProperty method in the IAutomappingConfiguration. That would save me a convention and I wouldn't repeat myself.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    Five times two is what?