Open bjarnef opened 2 years ago
For now I use the following workaround:
sql.Where($"( upper({ReviewDto.TableName}.{SqlSyntax.GetQuotedColumnName("title")}) LIKE upper(@term) " +
$"OR upper({ReviewDto.TableName}.{SqlSyntax.GetQuotedColumnName("name")}) LIKE upper(@term) " +
$"OR upper({ReviewDto.TableName}.{SqlSyntax.GetQuotedColumnName("email")}) LIKE upper(@term) " +
$"OR upper(convert(nvarchar(4000), {ReviewDto.TableName}.{SqlSyntax.GetQuotedColumnName("body")})) LIKE upper(@term))", new { term = $"%{searchTerm}%" });
instead of:
sql.Where<ReviewDto>(x =>
x.Title.Contains(searchTerm) ||
x.Name.Contains(searchTerm) ||
x.Email.Contains(searchTerm) ||
x.Body.Contains(searchTerm)
);
Tricky one this, cause if you want to do a case insensitive like you need the upper. And the fact you have to cast it, means if it really had ntext/nvarchar(max) data in it, it wouldn't work.
If generating a SQL query using
Contains()
on a db column of typeNTEXT
the query breaks on SQL CE using NPoco v4.0.2which generate the following SQL query:
If I remove the wrapping
upper()
function around[review].[body]
it works. Alternatively cast the field,cast
orconvert
on[review].[body]
tonvarchar
before usingupper()
function.