"Argument data type ntext is invalid for argument 1 of upper function" when trying to add a third item to a filter

c# entity-framework linq

Question

I have been following the Contoso University tutorial on the ASP.NET website. I am trying to expand my skills and so decided to try adding a third option to the filter. The tutorial provides:

if (!String.IsNullOrEmpty(searchString))
{
    students = students.Where(s => s.LastName.ToUpper().Contains(searchString.ToUpper())
                           || s.FirstMidName.ToUpper().Contains(searchString.ToUpper()));
}

Let's say I've got a third column called Nickname. I tried adding this to the filter by adding an additional || operator:

if (!String.IsNullOrEmpty(searchString))
{
    students = students.Where(s => s.LastName.ToUpper().Contains(searchString.ToUpper())
                           || s.FirstMidName.ToUpper().Contains(searchString.ToUpper())
                           || s.Nickname.ToUpper().Contains(searchString.ToUpper()));
}

When I run with the third option added I get:

[SqlException (0x80131904): Argument data type ntext is invalid for argument 1 of upper function.]

What am I missing here? What do I need to learn next to help me understand more about what's happening here?

1
3
3/12/2013 2:51:15 PM

Popular Answer

I recall having problems with NTEXT columns before when using Entity Framework. To get around this, I now only ever use NVARCHAR(MAX). I am not sure whether that would help in your situation.. whether you are able to change the db type or not... otherwise, there is further info here:

Linq to Entities : using ToLower() on NText fields

2
5/23/2017 10:29:08 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow