Linq-to-Sql query advice please
- by Mantorok
Hi all
Just wondering if this is a good approach, I need to search for items containing all of the specified keywords in a space-delimted string, is this the right approach this?
var result = (from row in DataContext.PublishedEvents
join link in DataContext.PublishedEvent_EventDateTimes on row.guid equals link.container
join time in DataContext.EventDateTimes on link.item equals time.guid
orderby row.EventName
select new {row, time});
// Split the keyword(s) to limit results with all of those words in.
foreach(var keyword in request.Title.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
var val = keyword;
result = result.Where(row=>row.row.EventName.Contains(val));
}
var end = result.Select(row=>new EventDetails
{
Title = row.row.EventName,
Description = TrimDescription(row.row.Description),
StartDate = row.time.StartDate,
EndDate = row.time.EndDate,
Url = string.Format(ConfigurationManager.AppSettings["EventUrl"], row.row.guid)
});
response.Total = end.Count();
response.Result = end.ToArray();
Is there a slick Linq-way of doing all of this in one query?
Thanks