Use .Contains() in EF 6

c# contains entity-framework linq

Question

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

1
4
4/18/2016 12:10:09 PM

Accepted Answer

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

2
4/18/2016 10:29:12 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