2010-06-19 97 views
3

我正在使用夏普體系結構,並且在實體中使用了多個值對象。下面是一個明顯簡單的例子:使用fluent-nhibernate是否可以在實體內自動映射值對象?

public class Person : Entity 
{ 
    protected Person(){} 

    public Person(string personName) 
    { 
     this.PersonName = personName; 
    } 

    public virtual string PersonName { get; protected set;} 
    public virtual StreetAddress MailingAddress { get; set; } 
} 

public class StreetAddress : ValueObject 
{ 
    protected StreetAddress(){} 

    public StreetAddress(string address1, string address2, string city, string state, string postalCode, string country) 
    { 
     this.Address1 = address1; 
     this.Address2 = address2; 
     this.City = city; 
     this.State = state; 
     this.PostalCode = postalCode; 
     this.Country = country; 
    } 

    public virtual string Address1 { get; protected set; } 
    public virtual string Address2 { get; protected set; } 
    public virtual string City { get; protected set; } 
    public virtual string State { get; protected set; } 
    public virtual string PostalCode { get; protected set; } 
    public virtual string Country { get; protected set; } 
} 

這當然拋出:

An association from the table Person refers to an unmapped class: Project.Domain.StreetAddress
因爲所述AutoPersistenceModelGenerator僅包括與類型類IEntityWithTypedId <>。尚不清楚夏普體系結構如何預期這種共同條件得以實施。這是否必須用bazillion覆蓋來處理?

回答

4

你可以在AutoPersistenceModelGenerator的GetSetup()方法更改爲類似:

private Action<AutoMappingExpressions> GetSetup() 
    { 
     return c => 
        { 
         c.IsComponentType = type => type.BaseType == typeof (ValueObject); 
        }; 
    } 

我會嘗試讓我看到了這個覆蓋張貼信貸博客帖子。

3

你會想把它作爲一個組件映射。您可以使用Fluent NHibernate中的映射覆蓋來完成此操作。

相關問題