0

我現在有一個預約模式,如:NHibernate的映射許多孩子實體一個實體

public class RoomBooking : Entity, IBooking 
{ 
    public virtual Client Client { get; set; } 
    public virtual Address Address { get; set; } 
    public virtual IList<BookingPeriod> BookingPeriods{get;set;}... 


public class BookingPeriod : Entity 
{ 
    public virtual IEnumerable<IBooking> Bookings { get; set; } 
    public virtual DateTime StartTime { get; set; } 
    public virtual DateTime EndTime { get; set; }... 

預訂有許多與BookingPeriods一對多的關係。有三種不同類型的預訂可以製作,而且每種都有相關的類型。

將NHibernate映射到最佳方式是什麼?我目前正在使用S#arp,它利用了Fluent NHibernate的AutoMapping功能。這會給出Bookings屬性上的錯誤,因爲它試圖引用未映射的類(IBooking)。

+0

嗨大衛,弄來有機會看我的答案?只是想知道它是否有幫助? – Richard 2010-08-31 08:45:11

回答

1

如果您正在使用流利的NHibernate的,你可以做到這一點,它指定類名要映射的預訂量,而不是Automapper試圖映射到接口IBooking:

public class RoomBooking : Entity, IBooking 
{ 
    public virtual Client Client { get; set; } 
    public virtual Address Address { get; set; } 
    public virtual IList<BookingPeriod> BookingPeriods { get; set; } 

} 

public class RoomBookingMap : EntityMap<RoomBooking> 
{ 
    public RoomBookingMap() 
    { 
     Map(x => x.Client); 
     Map(x => x.Address); 
     HasManyToMany(x => x.BookingPeriods); 
    } 

} 

public class BookingPeriod : Entity 
{ 
    public virtual IEnumerable<IBooking> Bookings { get; set; } 
    public virtual DateTime StartTime { get; set; } 
    public virtual DateTime EndTime { get; set; } 
} 

public class BookingPeriodgMap : EntityMap<BookingPeriod> 
{ 
    public BookingPeriodgMap() 
    { 
     Map(x => x.StartTime); 
     Map(x => x.EndTime); 
     HasManyToMany<RoomBooking>(x => x.Bookings); 
    } 

} 
public class EntityMap<T> : ClassMap<T> where T : Entity 
    { 
     public EntityMap() 
     { 
      Id(x => x.Id) 
       .UnsavedValue(-1) 
       .Column("id"); 

     } 


    }