3
我必須列在傳統的模式,我想映射爲一個組件(又名值類型)。對組件/值類型的引用是私有的。如何使用Fluent NHibernate映射私有範圍的組件?
實體的代碼看起來像這樣:
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'
可以顯示完整的堆棧跟蹤?理論假設來自哪裏?我不認爲NH可以在沒有特殊攔截器的情況下處理'只讀貨幣' – Firo