views:

653

answers:

4

How can I map to a private field with fluent NHibernate AutoPersistenceModel?

    public class A
    {
        private List<B>  myField;

        public A()
        {
            myField = new List<B>();
        }

        public IList<B> MyBs
        {
            get { return myField; }
        }
    }

Is there a fieldconvention for the AutoPersistence model or do I have to use separate mappings for classes with fields?

+2  A: 

James Gregory just posted about a few workarounds for that here:

http://blog.jagregory.com/2009/01/13/fluent-nhibernate-mapping-private-and-protected-properties/

Dan Fitch
That's not about automapping.
Paco
+1  A: 

The answer:

It's not possible yet. Maybe I should submit a patch for it...

Paco
It's been a year, same problem still exists.
Mark Rogers
A: 

It's been a while since this question was asked, but it's probably worth posting this answer in case others find this question.

The Fluent NHibernate Wiki has some information on 3 possible workarounds.

http://wiki.fluentnhibernate.org/Fluent_mapping_private_properties

RR
That is not about automapping, but about manual mapping. I knew that before asking the question.
Paco
A: 

I know this is not does not answer the auto mapping, but to assist those who get this searching for private field mapping.

You can now use the following code:

public class A
{
    private List<B>  myBs;

    public A()
    {
        myField = new List<B>();
    }

    public IList<B> MyBs
    {
        get { return myField; }
    }
}

With a mapping like this

public class AMap : ClassMap<A> {
        public AMap() {
            HasMany(x => x.MyBs).Access.CamelCaseField()
        }
}
Mike Glenn