How to Use Where clause in Linq ?
Are you looking for a way to Use Where clause in Linq ? then read this thread to know more about it
hi all,
i written method to retrieve route stored in an database. route has sub entity called route country.country holds two rows one for arrival and another row for departure country.i want to get routes on given arrival and departure country Id's
.code i written as follows,
public IList<EuropeBus.Model.Domain.Route> ViewRouteOnArrCunAndDesCun(int arrcuntry, int descountry)
{
IList<EuropeBus.Model.Domain.Route> routeList = new List<EuropeBus.Model.Domain.Route>();
using (EuropeBus.Model.Domain.EuropeBusDataContext data = new EuropeBus.Model.Domain.EuropeBusDataContext())
{
System.Data.Linq.DataLoadOptions loadOptions = new System.Data.Linq.DataLoadOptions();
loadOptions.LoadWith<EuropeBus.Model.Domain.Route>(o => o.Route_Countries);
loadOptions.LoadWith<EuropeBus.Model.Domain.Route_Country>(or => or.MDM_City);
loadOptions.LoadWith<EuropeBus.Model.Domain.MDM_City>(oc => oc.MDM_Country);
loadOptions.LoadWith<EuropeBus.Model.Domain.Route>(o => o.Route_Days);
data.LoadOptions = loadOptions;
var r = from ru in data.Routes orderby ru.RouteCode select ru;
if (r != null)
{
foreach (EuropeBus.Model.Domain.Route route in r)
{
routeList.Add(route);
}
}
}
return routeList;
the problem is how and where to put where clause.
thanks