1

好吧,這可能是一個雙重問題。我有一個類User,其中包含UserLocation類型的屬性Location。起初,我是映射UserUserLocation類和存儲他們無論是在分貝,但並沒有做出很大的意義對我來說,因爲對於UserLocation的唯一目的是爲了部分的User。不管怎樣,現在,我的映射是這樣的:流利的nhibernate映射嵌套屬性「找不到getter」

public class UserMap : ClassMap<User> 
    { 
     public UserMap() 
     { 
      Id(x => x.Id).Access.ReadOnlyPropertyThroughLowerCaseField().GeneratedBy.Identity(); 
      Map(x => x.Location.Address); 
      Map(x => x.Location.City); 
      Map(x => x.Location.State); 
      Map(x => x.Location.ZipCode); 
     } 
    } 

但我得到的錯誤「無法爲UserLocation.Address找到消氣」。我也得到了一堆鑄造錯誤,因爲看起來NHibernate還在爲UserLocation生成一個計算類。所以我想這個問題是什麼是從映射的內引用非映射自定義類的最佳方式。

哦,剛剛添加,我很確定UserLocation沒有被映射到任何地方。我甚至試圖從User映射中引用它,並且仍然嘗試將計算出的類轉換爲實際的類。我不可能理解爲什麼在這一點上甚至會有計算類型..

回答

8

你在那裏有一個component。組件在NHibernate中分別映射。

你的功能NHibernate映射應該是這樣的:

public class UserMap : ClassMap<User> 
{ 
    public UserMap() 
    { 
     Id(x => x.Id).Access.ReadOnlyPropertyThroughLowerCaseField() 
      .GeneratedBy.Identity(); 

     Component(x => x.Location, 
      loc => 
      { 
       loc.Map(x => x.Address); 
       loc.Map(x => x.City); 
       loc.Map(x => x.State); 
       loc.Map(x => x.ZipCode); 
      }); 
    } 
} 
+0

muchos格拉西亞斯! – 2012-08-09 14:16:43

+0

小字體,hehehe,它不是「muchos」,而是西班牙語中的「muchas」,因爲「gracias」是「女性性別」中的一個詞。 「Muchas gracias」。 – 2013-06-19 14:45:06