2009-07-11 74 views
0

我使用FluentNHibernate,但NHibernate的XML會做。NHibernate與屬性是類的模型

說我有這個模型

public User 
{ 
    public User() 
    { 
     ProfilePicture = new Picture(); 
    } 
    public Guid Id { get; private set; } 
    public Picture ProfilePicture { get; set; } 
} 

public Picture 
{ 
    int width; 
    int height; 
} 

我如何告訴NHibernate的如何存儲和retrive的ProfilePicture?

我知道流利它像

Map(x => x.ProfilePicture); 

但是,這並不工作。

回答

2

如果用戶和ProfilePicture來自兩個不同的表,那麼你應該使用References:如果您需要指定列名這是

References(x => x.ProfilePicture); 

(例如)

References(x => x.ProfilePicture, "ProfilePictureId"); 

還有其他幾個例子用於documentation中的不同用例。

如果ProfilePicture存儲在用戶表,那麼你將它映射爲Component

Component(x => x.ProfilePicture, c => 
    { 
     c.Map(x => x.width); 
     c.Map(x => x.height); 
    }); 
+0

我將使用組件。我如何知道命名約定? – 2009-07-11 12:54:00