如何使用Fluent NHibernate映射具有私有作用域的组件?
我已经找到了遗留模式中的列,我希望将其映射为组件(也称为值类型)。对组件/值类型的引用属于私有范围 实体代码如下所示:如何使用Fluent NHibernate映射具有私有作用域的组件?,nhibernate,fluent-nhibernate,nhibernate-mapping,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,我已经找到了遗留模式中的列,我希望将其映射为组件(也称为值类型)。对组件/值类型的引用属于私有范围 实体代码如下所示: public class Allocation : Entity<int> { //... private readonly Money price; protected Allocation() {} /* for NH only */ public Allocation(/* ... */ Money price) {
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();
});
当前映射如下所示:
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();
});
IUserType可能会有所帮助,然后可以在NullSafeGet/set方法中新建Money实例
您能显示完整的堆栈跟踪吗?argumentexception从何而来?我不认为NH可以在没有特殊拦截器的情况下处理
只读货币