Reputation: 6202
I have a database created with SQLite
in my C#
project. In a function, I like to filter the record in a table using Linq
. For this reason, using this code for the And function, I wrote
Expression<Func<Word, bool>> fnz = w => w.CreatedAt >= dt && w.CreatedAt < endDate;
if (!string.IsNullOrEmpty(username))
{
Expression<Func<Word, bool>> fnz2 = w => w.CreatedBy.Trim() == username;
fnz = fnz.And(fnz2);
}
If I use some string
functions like Trim()
, I get this error
wrong number of arguments to function trim()
I saw other posts related to this error but not with Linq
.
Upvotes: 1
Views: 64
Reputation: 301
Not sure if this helps but in EntityFramework with MSSQL, LINQ/lambda expressions are run against the database before the round trip which means that they are (tried to) being converted into SQL syntax. I don't know if in your code the database round trip has already occurred, but if not, I would suspect that your code tries to convert the string.Trim()
to SQLite syntax, which appears to exist but with different overloads.
Besides, is the w.CreatedBy.Trim()
really necessary? Are you really expecting values in you database to have trailing whitespaces?
If so, guarding my point from above, you would have to change your code to make the database round trip first (e.g. by calling .ToList()
) and then filter using your expression. Keep in mind that this could potentionally result in a large amount of data being passed from the database into memory.
Upvotes: 0