Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want my code to not only match exact result, but also LIKE result. How can I edit my LINQ to SQL query so it aslo searches for LIKE results?

[OperationContract]
List<SearchForVessel> GetSearchForVessel(string inpQuery)
{
  PositionDataClassesDataContext context = new PositionDataClassesDataContext();
 
  var res = from etas in context.Lloyds_ETAs
  join vessels in context.Lloyds_Vessels on etas.ImoNumber equals vessels.imo_no
  where etas.ImoNumber.Equals(inpQuery)
  select new SearchForVessel
{
  Vessel_ID = etas.Vessel_ID,
  ImoNumber = etas.ImoNumber,
  Vessel_Name = etas.Vessel_Name,
  Last_Place = etas.Last_Place,
  Last_Place_Location = etas.Last_Place_Location
};
return res.ToList();
}
Posted
Updated 20-Feb-13 10:55am
v2

1 solution

Change the where etas.ImoNumber.Equals(inpQuery) to where etas.ImoNumber.Contains(inpQuery)
 
Share this answer
 
Comments
Solo1233211 21-Feb-13 10:44am    
It works if etas.ImoNumber had been a String, but it is a INT... :-/
Mycroft Holmes 21-Feb-13 19:14pm    
Well that was obvious, the variable is a string and you want to do a string function duh! You will need to change the int to a string to be able to use a string function on it (.Contains or LIKE).

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