如何使用Fluent Nhibernate访问基类的背景字段?
-
04-10-2019 - |
题
如何在映射类中设置访问策略以指向基本_photos字段?
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;}
}
我目前正在使用以下操作来定位背景字段,但是由于找不到它,因此会抛出一个例外。
public class ArticleMap : ClassMap<Article>
{
HasManyToMany(x => x.Photos)
.Access.CamelCaseField(Prefix.Underscore) //_photos
//...
}
我尝试将后台_PhotoS直接移入类,并且访问作品起作用。那么如何访问基类的背景字段?
解决方案
好的找到答案。使用Fluent Nhibrenate版本1.1(2010年5月23日发布),您可以使用揭示成员方法:
Reveal.Member<YourEntity>("_privateField");
因此,上述映射类现在变为:
public class ArticleMap : ClassMap<Article>
{
HasManyToMany<Photo>(Reveal.Member<Article>("_photos"))
//...
}
发布详细信息: http://fluentnhibernate.org/blog/2010/05/23/feature-focus-fields.html
其他提示
尝试更改可访问性 _photos
受保护:
protected IList<Photo> _photos;
不隶属于 StackOverflow