Search code examples
nhibernatenhibernate-mappingcamelcasing

NHibernate: why field.camelcase?


Can someone tell me why in NHibernate mapping we can set access="field.camelcase", since we have access="field" and access="property"?

EDIT: my question is "why we can do this", not "what does it mean". I think this can be source of error for developper.


Solution

  • I guess you wonder what use field.camelcase have when we can do the same with just field? That's true, but that would give (NH) properties unintuive names when eg writing queries or reference the property from other mappings.

    Let's say you have something you want to map using the field, eg

    private string _name;
    public string Name { get { return _name; } }
    

    You sure can map the field using "field" but then you would have to write "_name" when eg writing HQL queries.

    select a from Foo a where a._name = ...
    

    If you instead using field.camelcase the data, the same query would look like

    select a from Foo a where a.Name...
    

    EDIT I now saw you wrote "field.camelcase" but my answer is about "field.camelcase-underscore". The principles are the same and I guess you get the point ;)