tags:

views:

219

answers:

3

Hello,

In my class i have the following property:

Class A
{
    public virtual string Tag
        {
            get; private set;
        }
}

And in my hbm.xml i have the following (which does not work)

<property name="Tag" access="nosetter.camelcase" />

Nhibernate can't find the backing field. Does anybody known which access strategy to use (if any)??? Thanks in advance.

A: 

Pretty sure that's having to be public.

There could be something done with explicit private fields and possibly another variable, but would want to know why you want the setter to be private ?

dove
+1  A: 

If you are using access property you need to have backing field for this public property. And also use protected modifier instead of private.

Sly
A: 

I had this issue. I wrote a blog post explaining my answer, but I say use protected for the setter.

Tim Hoolihan
Good read Tim. However, you conclude the post with "Why not set protected? It’s not unreasonable to expect a maintaining developer to understand that NHibernate sub-classes your class." While I agree that's a reasonable demand, a developer may still not want *other subclasses* to be able to set the value.
Jeff Sternal