开发者

How to map a component with private scope with Fluent NHibernate?

开发者 https://www.devze.com 2023-04-03 11:26 出处:网络
I\'ve got to columns in a legacy schema, that I\'d like to map as a component (aka value type). The reference to the component/value type is of private scope.

I've got to columns in a legacy schema, that I'd like to map as a component (aka value type). The reference to the component/value type is of private scope.

The entity cod开发者_Go百科e looks like so:

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

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

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

The value type code looks like so:

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

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

The current mapping looks like so:

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

Currently, the code above throws the following exception:

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


an IUserType could help, you could then new up the Money instance in the NullSafeGet/set Methods.

there's some links to a money usertype in here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号