Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got an exception "
An exception was thrown while attempting to evaluate a LINQ query parameter expression. To show additional information call EnableSensitiveDataLogging() when overriding DbContext.OnConfiguring.


My code:
C#
var temp = db.MyTable.Where(x => x.id == y.Value && z.Name == "Score")
                      .FirstOrDefault();
 if(temp ! = null)
     myDto.Score = temp.Value


What I have tried:

I already checked the temp null.
Posted
Updated 15-Apr-20 21:35pm
Comments
phil.o 7-Sep-19 12:36pm    
Chances are, the z variable is not related to anything.

With EF, keep in mind that ANYTHING you put in the Where clause will be converted to the SQL language of the backing database engine.

Anything on the left side of a comparison refers to a column in your database table. You can pass values in on the right side of the comparison, so long as it's convertible to SQL code.

In your case, the EF has no idea what "z" refers to your database table.
 
Share this answer
 
I too got the same exception, but not every time. Even I will check for the null value of that object the same as this, Can anyone suggest the best result. Check the query, how I implemented it in my code.

var temp = db.MyTable.Where(x => x.id == y.Value && x.Name == "Score")
.FirstOrDefault();
if(temp ! = null)
myDto.Score = temp.Value
 
Share this answer
 
Comments
CHill60 16-Apr-20 4:18am    
If you have a question then use the red "Ask a question" link at the top of the page. Do not use the "Add a Solution" link to another post, nor start typing in the "Add your solution here" input box, unless you are trying to answer a question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900