Consider a table with two columns: ID (int) and Role (string). Both values ββare zero.
Now suppose the data is in two columns:
ID Role -- ---- 1 NULL 2 Admin
The request is as follows:
List<types> t1 = ( from a in datacontext.RoleTable where a.Role != "Admin" select a ).ToList();
I thought the above query should return the first record of the table, since the Role column is not equal to "Admin", but the query returns an empty list.
Now when I use this query:
List<types> t2 = ( from a in datacontext.RoleType where a.Role != "Admin" && a.Role == DBNull.Value.ToString() select a ).ToList();
I get the correct answer.
Can someone tell me why the first request is not working please.
FYI: If the Role column in the first row of the table is changed to User instead of NULL , then the first query will work fine.
I am using SQL Express and LINQ to SQL.
source share