Как сопоставить компонент с частной областью с Fluent NHibernate? - PullRequest
3 голосов
/ 06 сентября 2011

Я получил столбцы в устаревшей схеме, которые я хотел бы отобразить как компонент (он же тип значения) Ссылка на тип компонента / значения имеет частную область.

Код объекта выглядит так:

public class Allocation : Entity<int>
{
    //...
    private readonly Money price;

    protected Allocation() {} /* for NH only */

    public Allocation(/* ... */ Money price)
    {
        //...
        this.price = price;
    }
}

Код типа значения выглядит так:

public struct Money
{
    private readonly decimal amount;
    private readonly int currencyId;

    public Money(decimal amount, int currencyId)
    {
        this.amount = amount;
        this.currencyId = currencyId;
    }
}

Текущее отображение выглядит так:

Component(Reveal.Member<Allocation, Money>("price"), 
          p =>
          {
             p.Map(Reveal.Member<Money>("amount")).Column("CURRENCY_PRICE").Not.Nullable();
             p.Map(Reveal.Member<Money>("currencyId")).Column("CURRENCY").Not.Nullable();
          });

В настоящее время приведенный выше код вызывает следующее исключение:

System.ArgumentException : Expression of type 'System.Object' cannot be used for return type 'BI.IPM.Services.TradeAllocation.Domain.Entities.Money'

1 Ответ

0 голосов
/ 23 апреля 2013

IUserType может помочь, вы можете затем создать экземпляр Money в NullSafeGet / set Methods.

здесь есть несколько ссылок на тип пользователя money.

...