3

查詢我映射我的價值目標項作爲組分的任意不等階如下因素映射配置的值對象的父對象空NHibernate的組件映射:在從數據庫

{ 
      Table("Product"); 
      Not.LazyLoad(); 
      Id(x => x.Id, "id"); 
      Map(x => x.Number, "number"); 
      Map(x => x.Name, "name"); 
      Map(x => x.Description, "description"); 
      Map(x => x.Status, "status"); 
      HasMany(x => x.ItemLines).Component(
       m => 
       {                    
         m.Map(x => x.ItemId, "itemid"); 
         m.Map(x => x.Qty, "quantity");      
        }).Table("productitems").KeyColumn("itemid"); 
     } 

Class structure 


public class ItemLine 
{ 
    public Product Product { get; set; } 
    public Guid ItemId { get; set; } 
    public int Qty { get; set; } 




    public ItemLine() 
    { 

    } 
    public ItemLine(Product product, Guid itemId, int qty) 
    { 
     Product = product; 
     ItemId = itemId; 
     Qty = qty; 

    } 

//Equality and GetHashCode implemented..... 


} 

我能夠將數據插入到數據庫中,但在檢索回來產品ID,項目行中的產品屬性爲空。

我需要通過任何引用的映射>

請幫

謝謝

回答

5

確定。通過試驗和錯誤解決。

Add m.ParentReference(x => x.Product);

{ 
      Table("Product"); 
      Not.LazyLoad(); 
      Id(x => x.Id, "id"); 
      Map(x => x.Number, "number"); 
      Map(x => x.Name, "name"); 
      Map(x => x.Description, "description"); 
      Map(x => x.Status, "status"); 
      HasMany(x => x.ItemLines).Component( 
       m => 
       {                     
         m.Map(x => x.ItemId, "itemid"); 
         m.Map(x => x.Qty, "quantity"); 

         m.ParentReference(x => x.Product); 


        }).Table("productitems").KeyColumn("itemid"); 
     } 

希望這可以幫助別人。