Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument data type text is invalid for argument 1 of lower function

In my application's search function, I have implemented a search function which executes the following statement against the database.

resultsquery = db.DBMovies.Where(m => (m.Actors.ToLower()).Contains(q.ToLower()))

In the part q.ToLower() I read the url parameter q and converts into lowercase and find it in the relevant database column. In my database, the column 'Actors' is of type 'text' rather than varchar. When I run my application, I get an exception called Argument data type text is invalid for argument 1 of lower function. Is there any way that I can avoid this exception? I prefer a way that I can solve it in a single line.

Thank you.

like image 285
Deepal Avatar asked Mar 27 '14 10:03

Deepal


2 Answers

Just change the datatype of your column in database to NVARCHAR(MAX) and your code will work like a charm. It's a known issue, if you do some googling. For instance please have a look here.

like image 190
Christos Avatar answered Oct 23 '22 12:10

Christos


You can simply convert the column to a VARCHAR - Something like this:

ALTER TABLE DBMovies
ALTER COLUMN Actors VARCHAR(MAX)
like image 1
Donal Avatar answered Oct 23 '22 12:10

Donal