I was working on an entity framework project and I wanted to do a LINQ Where() clause that has a contains based on the string state of an entity passed in as an enum.
string strState = state.ToString(); //convert enum to string
var logs = await _context.DispatchChangeLogs.Where(x => x.NewValues.Contains(strState)).ToListAsync();
This returns the error:
Argument data type text is invalid for argument 1 of charindex function.
In the above example, the strState value is "Approved". When I put "Approved" directly into the Contains method, it returns that set of values I am looking for with this query.
I found this article that gives a good explanation on the issue.
I changed the NewValues type in the database to varchar(max) and nvarchar(max) as a test. I updated my VS database project and republished to my local database. The database shows it as nvarchar(max).
The target framework for the DB project is .Net Framework 4.5.2
Any thoughts on why this would still be returning that "data type text" error?