My case description: In my C# and LINQ to SQL application, I am implementing FeserWard.Controls Intellibox. For a sales of handphone, user will type in handphone's IMEI in the intellibox and the box will do search in Table Handphone to look for the user input IMEI and finally display the exact match IMEI record.
Problem: I want to filter out all the (Handphone.IMEI) with status=Available (Item.I_Status="Available"), and from there, when user typing in IMEI, the intellibox list will do search only from the Available IMEI.
SQL
select h.HP_ID, h.IMEI, h.Colour, i.I_Status
from Item i, Handphone h
where i.I_ID = h.HP_ID AND i.I_Status='Available'
I want to replace IEnumerable DoSearch's LINQ with this but stuck.
var availableIMEISearch = from i in dataContext.Items.ToList()
join h in dataContext.Handphones.ToList()
on i.I_ID equals h.HP_ID
where(h.IMEI.StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase)) && (i.I_Status=="Available")
select new { i, h };
return availableIMEISearch;
Current workable method: IEnumerable DoSearch
DataClasses1DataContext dataContext = new DataClasses1DataContext();
public IEnumerable DoSearch(string searchTerm, int maxResults, object extraInfo)
{
var imeiSearch = dataContext.Handphones.ToList()
.Where(h => h.IMEI.StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase));
return imeiSearch;
}
Table1:
Item (PK = I_ID)
Table2:
Handphone (PK,FK1 = HP_ID), where Item.I_ID = Handphone.HP_ID