Click here to Skip to main content
12,621,155 members (33,135 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# LINQ Silverlight
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 20-Feb-13 11:54am
Updated 20-Feb-13 11:55am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Change the where etas.ImoNumber.Equals(inpQuery) to where etas.ImoNumber.Contains(inpQuery)
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161128.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100