2010-06-19 2 views
3

저는 Sharp Architecture를 사용하고 있으며 Entity에서 Value Objects를 사용하는 경우가 많습니다.Fluent-nhibernate를 사용하면 Entity 내부에서 Value Object를 자동으로 매핑 할 수 있습니까?

물론
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을 포함하기 때문에 여기서 명백한 간단한 예이다. 샤프 아키텍처 (Sharp Architecture)가이 공통 조건이 어떻게 구현 될 것으로 기대되는지는 분명하지 않습니다. 이것은 bazillion overrides로 처리해야합니까?

답변

4

당신이 좋아하는 뭔가 AutoPersistenceModelGenerator에서 GetSetup() 메소드를 변경할 수 있습니다 : 나는이 신용 게시 커버 본 블로그 게시물을 얻기 위해 노력할 것이다

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

.

3

이 구성 요소를 매핑해야합니다. Fluent NHibernate에서 매핑 오버라이드를 사용하여이를 수행 할 수 있습니다.

1

나는 Alec에 동의합니다. 나는이를 컴포넌트로 매핑 할 것이다. 이

AutoMapping a Composite Element in Fluent Nhibernate

, 당신은 또한 복합 요소의 컬렉션을 매핑하는 방법에 대한 정보를 찾을 수 있습니다 :

는에 대한 자세한 내용은이 SO 질문을 참조하십시오.