【问题标题】:Fluent NHibernate - recursive mapsFluent NHibernate - 递归映射
【发布时间】:2009-07-13 03:47:53
【问题描述】:

我有一个代表位置的对象。位置可以包含其他位置。我如何用 Fluent NHibernate 表示这种关系。该类如下所示:

public class Location : EntityBase
{
    #region Properties
    public string LocationName { get; set; }
    public Location ParentLocation { get; private set; }

    private List<Location> _locations = new List<Location>();
    public IEnumerable<Location> Locations
    {
        get { return _locations; }
    }

    private List<Device> _devices = new List<Device>();
    public IEnumerable<Device> Devices
    {
        get { return _devices; }
    }

    #endregion
    //Other logic omitted
}

谢谢。

【问题讨论】:

  • 您当前的映射是什么?为什么 HasManyToMany(map => map.Locations) 不起作用?
  • @Paco:属性 Locations 需要一个 setter 才能使用 Fluent NHibernate。

标签: nhibernate recursion fluent


【解决方案1】:

可以获取私有字段

HasManyToMany(Member.Reveal<Location>("_locations"))

【讨论】:

    猜你喜欢
    • 2011-04-10
    • 1970-01-01
    • 2011-06-18
    • 2012-04-03
    • 2012-10-19
    • 2013-01-07
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多