我正在使用 Sharp Architecture,并且在许多情况下,值对象都在实体中使用。这是一个明显的简单示例:
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; }
}
这当然会抛出:
来自表 Person 的关联引用了一个未映射的类:Project.Domain.StreetAddress因为 AutoPersistenceModelGenerator 只包含类型为 IEntityWithTypedId<> 的类。目前尚不清楚 Sharp Architecture 期望如何实现这种常见条件。这是否必须通过无数次覆盖来处理?