4
votes

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?

3

3 Answers

1
votes

The answer:

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

0
votes

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()
        }
}
-2
votes

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