[英]System.NotSupportedException: How to simplify the NHibernate Query?
How to simplify the below query in NHibernate? 如何在NHibernate中简化以下查询?
Below is the logic to find the Max value between 3 different products and order them by the Max value. 以下是在3种不同产品之间找到最大值并按最大值排序的逻辑。
IQueryable<Property> results = ISession.Get<Property>();
results = from r in results
let pdts = new List<decimal?> { r.Prod1.Rate, r.Prod2.Rate, r.Prod3.Rate }
let max = pdts.Max()
orderby max
select r;
When executing it, NHibernate is throwing an error System.NotSupportedException
with the exceptionMessage 在执行它时,NHibernate抛出一个异常
System.NotSupportedException
和exceptionMessage。
"exceptionMessage": "new List
1() {Void Add(System.Nullable
1[System.Decimal])([100001].Prod1.Rate), Void Add(System.Nullable1[System.Decimal])([100001].Prod2.Rate), Void Add(System.Nullable
1[System.Decimal])([100001].Prod3.Rate)}", "exceptionType": "System.NotSupportedException",“ exceptionMessage”:“新列表
1() {Void Add(System.Nullable
1 [System.Decimal])([100001] .Prod1.Rate),无效添加(System.Nullable1[System.Decimal])([100001].Prod2.Rate), Void Add(System.Nullable
1 [System.Decimal])([100001.Prod3.Rate)}“,” exceptionType“:” System.NotSupportedException“,
How can I simplify this query as the logic is perfect? 由于逻辑完美,如何简化此查询?
The reason is that NHibernate cannot generate the SQL from your Linq because of the List initialization is. 原因是由于List的初始化,NHibernate无法从您的Linq生成SQL。
Try this: 尝试这个:
results = from r in results
let max = (r.Prod1.Rate >= r.Prod2.Rate && r.Prod1.Rate >= r.Prod3.Rate) ? r.Prod1.Rate
: (r.Prod2.Rate >= r.Prod1.Rate && r.Prod2.Rate >= r.Prod3.Rate) ? r.Prod2.Rate
: r.Prod3.Rate
orderby max
select r;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.