【问题标题】:Fluent Nhibernate: how to map bidirectional relationshipFluent Nhibernate:如何映射双向关系
【发布时间】:2012-12-11 00:43:14
【问题描述】:

我正在尝试映射以下内容,但不确定当前的 nHibernate/fluent nHibernate 是否可行,因此非常感谢任何建议。

基本上我有以下 2 个类

public class Venue
{
    public virtual int ID {get;set;}
    public virtual VenueDetail CurrentDetails {get; set;}
    public virtual IEnumerable<VenueDetail> PreviousDetails {get; set;}
}

public class VenueDetail
{
    public virtual int ID {get;set;}
    public virtual string Description {get;set;}
    public virtual Venue Venue {get;set;}
}

有没有办法有效地映射上述关系?我的 Venue 表有一个指向 CurrentVenueDetails 属性的 VenueDetail 的外键,同时我的 VenueDetail 也有一个指向 Venue 属性的 Venue 表的外键。

干杯

【问题讨论】:

    标签: c# nhibernate fluent-nhibernate fluent-nhibernate-mapping bidirectional-relation


    【解决方案1】:

    It is pretty much all described here for you.

    public class VenueDetailMap : ClassMap<VenueDetail>
    {
        ....
        //Reference the One side of the OneToMany
        Reference(x => x.Venue);
        ....
    }
    
    public class VenueMap : ClassMap<Venue>
    {
        ....
        //Declare this is the many side
        HasMany(x => x.PreviousDetails);
        // We are referencing another entity here
        References( x => x.CurrentDetails);
        ....
    }
    

    【讨论】:

      猜你喜欢
      • 2010-11-25
      • 2011-12-01
      • 2010-09-23
      • 1970-01-01
      • 2011-04-10
      • 2011-07-11
      • 1970-01-01
      • 2012-07-26
      • 2011-03-02
      相关资源
      最近更新 更多