This code runs fine in the SQL Server Management Studio:
SELECT [PassNumber] FROM [dbo].[Customers] WHERE [PassNumber] <> 'A'
This code also works as expected:
string query = "PassNumber <> 'A'";
DbSqlQuery<Customer> data = db.Customers.SqlQuery( string.Format("select * from customers where {0}", query) );
Now it is changed to exclude empty rows and this code works fine on SSMS:
SELECT [PassNumber] FROM [Customers] WHERE [PassNumber] <> ''
But I can't find a way to correctly format the query string. I have tried all possible combinations that I thought of, but the code throws an exception: "Incorrect syntax near the keyword '<>'."
string query = "PassNumber <> '' ";
DbSqlQuery<Customer> data = db.Customers.SqlQuery( string.Format("select * from customers where {0}", query) );
NOTE: For simplicity, the check for null value has been left out of the examples in the question.