Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 976
G43beli Avatar asked Oct 30 '22 05:10

G43beli


1 Answers

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

like image 167
Vladimir Avatar answered Nov 15 '22 06:11

Vladimir