LinQ select on a condition over an EntitySet RRS feed

  • Question

  • Hello,

    I have these two SQL Tables: Employees and EmpTasks . Employee has a PrimayKey, int Id, LastName and FirstName. EmpTasks has it's own Id, EmployeeId int, DateDue DateTime and Closed as boolean.

    As I said, I have mapped these two tables with two classes, Employee and Task.

    I also have a property TaskList in Employee returning values from an EntitySet<Task> associated over those tables.

    The mapping is OK, it works fine when I  "from emp in dataContext.Employees select emp" but I would like to select only those employees having at least one active task in the TaskList (i.e. Closed==false ). Any idea on how can I do that?

    Thank you,

    Wednesday, October 24, 2018 11:44 AM


  • Hi dcristut,

    We could achieve it by using Any method, Here is sample for your reference.

     using (var dataContext = new DataClassesDataContext())
          var result = dataContext.Employees.Where(t => t.EmpTasks.Any(x => x.Closed == false)).ToList();

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    • Marked as answer by dcristut Wednesday, April 10, 2019 9:32 AM
    Thursday, October 25, 2018 1:33 AM