我将poco对象映射到数据库,如下所示:
class MoneyObject
{
Money MoneyAmmount { get;set; }
string Description { get;set; }
}
moneyammount-是从ICompositeUserType派生的money类型,具有两个属性:十进制金额和字符串货币代码:
class Money
{
decimal Ammount { get;set; }
string CurrencyCode { get;set; }
}
当我试图使用以下条件从数据库中获取数据时,会出现问题:
var criteria = session.CreateCriteria(typeof(MoneyObject))
.Add(Expression.Lt("MoneyAmmount", money));
它生成以下SQL查询:
SELECT this_.Id as Id2_0_, this_.Value as Value2_0_, this_.Currency as Currency2_0_, this_.Description as Descript4_2_0_
FROM MoneyObject this_
WHERE this_.Value < @p0 and this_.Currency < @p1;@p0 = 300,01, @p1 = 'USD'
我不想使用currencycode逐字符比较我的valuetype对象货币。我只想按金额属性比较货币,并使用条件获取数据。但是只处理POCO对象的属性。意思是我知道比较是有效的:
Expression.Lt("MoneyAmmount.Ammount", money.Ammount)
我希望避免按ValueType对象属性进行比较,并且仅在以下类型的ValueType对象之间实现比较
Expression.Lt("MoneyAmmount", money)
有人知道如何改变这种比较行为吗?