This is a migrated thread and some comments may be shown as answers.

Directly parameterized literal boolean eq/neq expression found

2 Answers 69 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard Koslik
Top achievements
Rank 1
Richard Koslik asked on 18 Nov 2011, 10:33 AM
Hello,
today i have installed the new Q3 release...now my code does not work anymore (before Q3 it worked!)...

Following error is thrown:
An exception occured during the execution of '
Extent<Web.PORDER>().Where(po => ((((((po.PORDER_S_KEY == value(Klassen.clPRIN+<>c__DisplayClass47).sOrderKey) AndAlso ((Convert(po.PORDER_B_LOCKED) == null) OrElse (Convert(po.PORDER_B_LOCKED) == Convert(0)))) AndAlso ((po.PORDER_D_FROM == Convert(null)) OrElse (po.PORDER_D_FROM < Convert(DateTime.Now)))) AndAlso ((po.PORDER_D_TO == Convert(null)) OrElse (po.PORDER_D_TO > Convert(DateTime.Now.Date)))) AndAlso ((Convert(po.PORDER_B_NIGHT) == Convert(1)) OrElse (value(Klassen.clPRIN+<>c__DisplayClass47).bNightmode == False))) AndAlso value(Klassen.clPRIN+<>c__DisplayClass47).lOrdertypes.Contains(po.PORDER_I_TYPE))).Count()'.
Failure: Directly parameterized literal boolean eq/neq expression found; use integer type here.

Linq statement is following:
lOrdertypes is a List<short?>
bNightmode is a boolean
  
var query = from po in iclDB.dbContext.PORDERs
 where po.PORDER_S_KEY == sOrderKey && (po.PORDER_B_LOCKED == null || po.PORDER_B_LOCKED == 0) &&
 (po.PORDER_D_FROM == null || po.PORDER_D_FROM < DateTime.Now) &&
 (po.PORDER_D_TO == null || po.PORDER_D_TO > DateTime.Now.Date) &&
 (po.PORDER_B_NIGHT == 1 || bNightmode == false) &&
 lOrdertypes.Contains(po.PORDER_I_TYPE)
select po;
  
if (query.Count() == 0) return "NOT_FOUND"; // order not found!

Why and where should i use a integer???!!!

regards
Richard.

2 Answers, 1 is accepted

Sort by
0
Richard Koslik
Top achievements
Rank 1
answered on 18 Nov 2011, 12:47 PM
Hello,

the problem is the boolean variable in the linq statement.
If it is changed to

    
    (po.PORDER_B_NIGHT == 1 ||

 

Convert.ToInt32(bNightmode) == 0) &&

the statement works.
But it can't be the solution to convert each used boolean variable to an integer...

regards
Richard.

 

0
Thomas
Telerik team
answered on 18 Nov 2011, 06:58 PM
Hello Richard Koslik,

I'm really sorry  about this regression. I can reproduce this here now. Our parameter detection is improved and the fixed condition is detected as literal, and generates the mentioned exception. I will try to fix this.
In the mean time you can do one of the following:
(a) Push the condition conditionally to the server: Either it is night mode, then generate one kind of query, or it is not night mode, then generate another kind of query. You can combine LINQ expressions.
(b) Use !bNightMode instead of bNightMode == false. The effect is the same, however the LINQ tree is slightly different and therefore the conditions are pushed to the server slightly different.

Again, my apologies for this regression. I've included dozens of tests for booleans for the release, but this form did not make it.

I've updated your Telerik points.
Regards,
Thomas
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

Tags
LINQ (LINQ specific questions)
Asked by
Richard Koslik
Top achievements
Rank 1
Answers by
Richard Koslik
Top achievements
Rank 1
Thomas
Telerik team
Share this question
or