Click here to Skip to main content
15,902,922 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone
C#
string userCond = string.Empty;
if (!string.IsNullOrEmpty(data.FirstName))
{
userCond = "FirstName ==\"" + data.FirstName + "\";

var query = from x in ctx.User_Users.Where(userCond)
select x;
}

When i execute above code it generates error mentioned below:

"FirstName' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly."

Is there any work around to this problem?
Posted
Updated 29-Jul-10 4:27am
v2

Is there any reason you can't use the lambda? For the code you've posted it seems as though you know you're working with the first name, anyways.

var query = ctx.User_Users.Where(u => u.FirstName == data.FirstName);


Cheers.
 
Share this answer
 
Basically what i want is to apply join and where clause dynamically based upon type of parameter selected by end user through user interface e.g if i have a table table1 with columns col1 and col2 and another table table2 with col1 (FK to col of table1) col3 and col4 and end user selects only parameter col of table1 then there should be only one column i.e col1 in the where clause and join but if user asks to search based on col1 of table1 and col3 of table2 then it requires both columns in the where clause as well as join.

Hope it clears the need.
 
Share this answer
 

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