0

我有一個表,例如User。 現在,在我的表Books,我需要映射兩個用戶領域使用FluentNHibernate對同一個表的兩個引用

public User Wants {get; set;} 
public User Read {get; set;} 

如何映射呢? (在這種情況下,舊版本的fluentnhibernate和automapping不起作用) 通常,答案需要與自動映射一起工作,因爲應用程序中的所有實體都使用自動映射。

回答

0

我認爲這是直截了當的。

public class BookMap : ClassMap<Book> 
{ 
    public BookMap() 
    { 

     /* all other mapping info */ 

     References<User>(x => x.Wants) 
      .Class(typeof(User)) 
      /*.Not.Nullable() */ 
      .Nullable() 
      .Column("WantsUserUUID") 
      .Index("IX_Book_WantsUserUUID") 
      .Cascade.SaveUpdate() 
      ; 
     ; 

     References<User>(x => x.Read) 
      .Class(typeof(User)) 
      /*.Not.Nullable() */ 
      .Nullable() 
      .Column("ReadUserUUID") 
      .Index("IX_Book_ReadUserUUID") 
      .Cascade.SaveUpdate() 
      ; 
     ; 
相關問題