gpt4 book ai didi

nhibernate - 如何使用 Fluent NHibernate 映射具有私有(private)作用域的组件?

转载 作者:行者123 更新时间:2023-12-02 11:06:48 26 4
gpt4 key购买 nike

我有旧模式中的列,我想将其映射为组件(也称为值类型)。对组件/值类型的引用属于私有(private)范围。

实体代码如下所示:

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'

最佳答案

用户类型会有所帮助,然后您可以在 NullSafeGet/set 方法中新建 Money 实例。

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

关于nhibernate - 如何使用 Fluent NHibernate 映射具有私有(private)作用域的组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7318282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com