I have a Task object that has a collection of Label objects … in the database the tables are called Task and Label.
There are a variety of ways to search for a Task, so using LINQ, I construct my LINQ query in an expression tree … similar to the below code sample:
IQueryable<Data.Task> query = ctx.DataContext.Tasks; if (criteria.Number > 0) query = query.Where(row => row.Number == criteria.Number); if (criteria.CustomerId != Guid.Empty) query = query.Where(row => row.Project.CustomerId == criteria.CustomerId); if (criteria.ProjectId != Guid.Empty) query = query.Where(row => row.ProjectId == criteria.ProjectId); var data = query.Select(row => TaskInfo.FetchTaskInfo(row)); this.AddRange(data);
This works great … but now I would like to search for Tasks with a specific Label, for example, accounting or feature-request.
I am able to do this in LINQPad from a complete query:
from t in Tasks join l in Labels on t.TaskId equals l.SourceId where l.Name == 'accounting' select t
Is there anyway to do this using an expression tree? I’m stuck! Any help would be greatly appreciated!
I believe this should do it: