Is there a function similar to Math.Max ​​for Entity Framework?

I have an entity structure query as follows:

From T In Db.MyTable
Where (T.Col1 - T.Col2) + T.Col3 - T.Col4 > 0 _
Select T

Now I need to make sure that the bracketed part of '(T.Col1 - T.Col2)' does not fall below zero.

In .Net, I would encode it like this (but obviously EF doesn't like Math.Max).

From T In Db.MyTable
Where Math.Max(T.Col1 - T.Col2,0) + T.Col3 - T.Col4 > 0 _
Select T

Is there an easy way to do this? I am using EF 2.0 (not the latest, just released version).

Thanks in advance

+3
source share
1 answer

Maxnot supported, but Abs- ; This will? Otherwise, you have to use a triple expression. In C #, I would do:

from t in Db.MyTable
let m = t.Col1 >= t.Col2 ? t.Col1 - t.Col2 : 0
where m + t.Col3 - t.Col4 > 0

, . .

+2

Source: https://habr.com/ru/post/1741257/


All Articles