문제

How do i set the Access Strategy in the mapping class to point to the base _photos field?

public class Content
{
  private IList<Photo> _photos;
  public Content()
  {
     _photos = new List<Photo>();
  }
  public virtual IEnumerable<Photo> Photos
  {
    get
    {
      return _photos;
    }
  }

  public virtual void AddPhoto() {...}
}

public class Article : Content
{
  public string Body {get; set;}

}

I am currently using the following to try and locate the backing field but an exception is thrown as it cannot be found.

public class ArticleMap : ClassMap<Article>
{
   HasManyToMany(x => x.Photos)    
   .Access.CamelCaseField(Prefix.Underscore)  //_photos
   //...
}

i tried moving the backing field _photos directly into the class and the access works. So how can i access the backing field of the base class?

도움이 되었습니까?

해결책

ok found the answer. Using Fluent NHibernate version 1.1 (released 23 May 2010) you can make use of the reveal member method:

Reveal.Member<YourEntity>("_privateField");

So the above mapping class now becomes:

public class ArticleMap : ClassMap<Article>
{
   HasManyToMany<Photo>(Reveal.Member<Article>("_photos"))
   //...
}

Release details: http://fluentnhibernate.org/blog/2010/05/23/feature-focus-fields.html

다른 팁

Try changing the accessibility of _photos to protected:

protected IList<Photo> _photos;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top