开发者

How to map private fields in FluentNHibernate using DefaultAutomappingConfiguration

The guidance given here http://fluentnhibernate.org/blog/2010/05/23/feature-focus-fields.html suggests that from V1.1 the automapping feature of Fluent NHibernate supports mapping to private fields.

So given the following code, NHiberate should be able to map to the myValue field.

public class SomeEntity
{   
   private string myValue;
   public virtual int Id { get; set; }
}

public class DomainAutomappingConfiguration : DefaultAutomappingConfiguration
{
    public override bool ShouldMap开发者_如何学C(FluentNHibernate.Member member)
    {
        return (member.IsProperty && member.IsPublic && member.CanWrite) ||
               (member.IsField && member.IsPrivate);
     }
 }

However when I run this code and try to map, I get the following exception:

NHibernate.PropertyNotFoundException : Could not find a getter for property 'myValue' in class.....

I am using FluentNHibernate 1.1 and NHibernate 3.0.0.2001

What am I doing wrong?


Change:

private string myValue;

To:

private string myValue {get;set;}

I am not sure if this will do it for you, but the error you are receiving is the lack of the {get;} when designating the private field. Hopefully this will put you on the right track. I have not tried mapping private fields.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜