score:7

Accepted answer

TEXT columns do not support the equal to operator, even in SQL.

You must make it so your query translates into a LIKE operator, which can be achieved with either Contains (LIKE '%str%'), StartsWith (LIKE '%str') or EndsWith (LIKE '%str').

If you need strict equality, something like this should work:

var result = db.Table.Where(x => x.columnA.StartsWith("A") &&
                                 x.columnA.EndsWith("A")).ToList();

score:3

you can use this (i haven't tested the code)

var result = db.Table.Where(x => x.columnA.Contains("A")).ToList();

score:2

Can you cast the Column in question to a string? I haven't got any way to test this as I don't have a DB with a Text type.

var result = db.Table.Where(x => x.columnA.ToString() == "A").ToList();

score:1

I tried all the above-mentioned solution and none of the fixes works for me, So here I am posting the fix which works for me

 var result = db.Table.Where(x => Convert.ToString(x.columnA) == "A").ToList();

score:0

I had the same issue and none of the string conversion solutions worked for me. The problem was that I had a 'text' data type for this column (because I migrated it from sqlite). Solution: just change the data type to `'nvarchar()' and regenerate the table.


Related Articles