How can I query on a table given as parameter? I just want to check if a record exists.
Example:
String query = "Select * from " + tableName + "t where t.ID='" + fieldvalue + "'";
Regards
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Gohil JayendrasinhPosted Jun 13, 2012, 2:38 AM
http://www.hanselman.com/blog/TheWeeklySourceCode48DynamicQueryableMakesCustomLINQExpressionsEasier.aspx
Ajay PatelPosted Jun 1, 2012, 3:22 AM
Glenn SanchezPosted Apr 2, 2012, 9:01 PM
Sorry for not being clear here. My exact concern is how/what type of class should I use for casting result for dynamic query with LINQ. This is what I mean:
String query = "Select * from " + tableName + "t (nolock) where t.ID='" + fieldvalue + "'";
var res = context.ExecuteQuery<ClassName>(query).ToList();
What should I use as class.
SenthilkumarPosted Mar 29, 2012, 3:26 AM
You can query like this.
Are you going to use the table is not constant? then
string query = "SELECT * FROM " + tableName + " where ID='" + fieldvalue + "'";
You know the table name
string query = "SELECT * FROM tableName WHERE ID='" + fieldvalue + "'";
If your id column is integer column then
string query = "SELECT * FROM " + tableName + " WHERE ID=" + fieldvalue;