Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
hi friends,

i am using mysql as back end and wpf asa front end in my program. in that i want to do

select * from mcs_Hall where mcs_Hall_Name = "%j%";
query. so i try this coding
string str = txt_Search.Text.Trim();
dataGrid1.DataContext = from re in MainWindow.mcsEntity.mcs_hall
                        where SqlMethods.Like(re.mcs_Hall_Name, "%j%")          
select new
{
  name = re.mcs_Hall_Name,
  code = re.mcs_Hall_Code
};     


but it throw this exception,...

LINQ to Entities does not recognize the method 'Boolean Like(System.String, System.String)' method, and this method cannot be translated into a store expression.

help me to do this.
Posted
Updated 26-Jan-17 3:16am
v3

http://stackoverflow.com/questions/2584598/linq-sqlmethods-like-fails

this article help me,.

LIKE 'a%' => StartsWith("a")
LIKE '%a' => EndsWith("a")
LIKE '%a%' => Contains("a")
LIKE 'a%b' => StartsWith("a") && EndsWith("b")
LIKE '%a%b%' => StartsWith("a") && Contains("b")


now my code is

dataGrid1.DataContext = from re in MainWindow.mcsEntity.mcs_hall re.mcs_Hall_Name.Contains(txt_Search.Text.Trim())


thank u very much,.
 
Share this answer
 
Comments
Avinash Ramchandra Shinde 22-May-13 1:12am    
thank you, very good solution
Usually, when I am totally clueless (which is the case most of times ;)), I copy the error message and look if there are other people having a similar problem.
This [^]is what I did in your case.

And the very first article[^] seems to be promising.
 
Share this answer
 
v2
Comments
Pravin Patil, Mumbai 1-Mar-11 6:43am    
Very good link manas...
Manas Bhardwaj 1-Mar-11 6:46am    
thanks!
Sagotharan Jagadeeswaran 1-Mar-11 6:50am    
thank u friend,.
Member 11233366 9-Mar-15 7:56am    
Dear i have to search *a*b*c* in a table column so please suggest a good solution i already wasted so much time on it.
Regards Wasif
Int32 case_id =( from c in db.CaseTLS
where SqlMethods.Like(c.TypeDescription, key3)
&& c.CaseNumber ==key1
&& c.Year == key2
select c.CaseId).FirstOrDefault();
where key3 contains that pattern but i am getting an exception on like method

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900