I am using wcf rest service. I am querying sql server database to return me rows from the table name which i pass from GUI. What happens is that sometimes table doesnt exist in database and i am using singleorDefault method of Linq. So if there is no table in database then it throws exception. How could i handle this? I still need to perform certain logic even if table is not found. Here is my code
var strTableQuery = "Select * from " + tableName // i get this tableName from my GUI
Tables = Context.Database.SqlQuery<TableClass>(strTableQuery );
var x = Tables.SingleorDefault(); // i get exception on this line
if (x != null){
// do some logic
} else {
//do some logic
}
Update1
I get exception as Invalid object name tableName