Click here to Skip to main content
Rate this: bad
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?

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
Edited 20-Feb-13 11:55am

1 solution

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

Solution 1

Change the where etas.ImoNumber.Equals(inpQuery) to where etas.ImoNumber.Contains(inpQuery)
Solo1233211 at 21-Feb-13 10:44am
It works if etas.ImoNumber had been a String, but it is a INT... :-/
Mycroft Holmes at 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)

Advertise | Privacy | Mobile
Web04 | 2.8.150302.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2015
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