With fluent-nhibernate, can I automate Value object (s) inside Entity?

I use Sharp Architecture and have a number of situations where Value objects are used in Entity. Here is a simple example:

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; }
}

This of course throws:

An association from the table Person refers to an unmapped class: Project.Domain.StreetAddress
because AutoPersistenceModelGenerator only includes classes of type IEntityWithTypedId <>. It is unclear how Sharp Architecture expects this general condition to be implemented. Does this need to be handled with bazillion overrides?
+3
source share
3 answers

You can change the GetSetup () method in AutoPersistenceModelGenerator to the following:

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

blogpost, , .

+4

. Fluent NHibernate .

+3

. .

. SO:

, .

+1

Source: https://habr.com/ru/post/1750767/


All Articles