G43beli
G43beli

Reputation: 3972

Use .Contains() in EF 6

I use the following Linq Query:

var projectList = from p in dbContext.vw_Projektkontrolle
                       where p.TXT_Adress1.Contains(filterTxt)
                       orderby p.TXT_Name
                       select p;

My projectList is always null. In the debugging I can see, that filterTxt is for example "testcompany".

Is the Contains method still in use in EF 6 or is there any work around?

I pass the filterTxt via Form Post to the Action Method in my MVC application.

how to fix this issue.

EDIT: it works when I use just one char f.ex: "a" as filterTxt.

But TXT_Adress1 and filterTxt are both declared as strings

Upvotes: 5

Views: 14653

Answers (1)

Vladimir
Vladimir

Reputation: 1390

String.Contains method translates to:

CHARINDEX(ShowTypeDescriptio, @showTypeDescription) > 0

Might try to use lower case:

var projectList = from p in dbContext.vw_Projektkontrolle
                   where p.TXT_Adress1.ToLower().Contains(filterTxt.ToLower())
                   orderby p.TXT_Name
                   select p;

And even if it works you might face Turkey Test issue

Upvotes: 2

Related Questions