映射组件集合中的组件

J F*_*des 11 nhibernate domain-driven-design fluent-nhibernate

我正在尝试映射一个值对象集合,其中包含其他值对象,但我得到以下异常.

nHibernate异常:

 ----> NHibernate.PropertyNotFoundException : Could not find a getter for property '_timeAtAddress' in class 'CustomerAddress'
Run Code Online (Sandbox Code Playgroud)

域:

public class CustomerAddress
{
    private TimePeriod _timeAtAddress;

    protected CustomerAddress() { }

    public CustomerAddress(TimePeriod timeAtAddress)
    {
        _timeAtAddress = timeAtAddress;
    }

    public TimePeriod TimeAtAddress { get { return _timeAtAddress; } }
}

public class TimePeriod
{
    private readonly int _months;
    private readonly int _years;

    protected TimePeriod() { }

    public TimePeriod(int months, int years)
    {
        _months = months;
        _years = years;
    }

    public int Months { get { return _months; } }
    public int Years { get { return _years; } }
}
Run Code Online (Sandbox Code Playgroud)

nHibernate映射:

contact.HasMany<CustomerAddress>(Reveal.Member<Contact>("_customerAddresses"))
    .Schema(...)
    .Table(...)
    .KeyColumn(...)
    .AsBag()
    .Not.LazyLoad()
    .Component(address =>
    {
        .
        .
        .

        address.Component(Reveal.Member<CustomerAddress, TimePeriod>("_timeAtAddress"), timeAtAddress =>
        {
            timeAtAddress.Map(Reveal.Member<TimePeriod>("_years")).Column("TIME_YEARS");
            timeAtAddress.Map(Reveal.Member<TimePeriod>("_months")).Column("TIME_MONTHS");
        });
    });
Run Code Online (Sandbox Code Playgroud)

快速浏览一下Access,但似乎无法弄清楚在哪里设置组件.你能帮我吗?

J F*_*des 1

我成功前进的唯一方法(使用私有字段)是设置全局 Access.Field 约定。

.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Customer>() .Conventions.Add(DefaultAccess.Field()))