How to Write This LINQ Query? RRS feed

  • Question

  • User-173651909 posted

    I need to construct a LINQ query to achieve the following:

    Imagine an SQL table (dbo.projects) which contains a "Username" field, the ID of which is linked to another table (dbo.tasks) containing the ProjectID.

    For each distinct user in projects, I need to return the username, and a count of the total tasks they've created.


    ID   Username
    1      user1    
    2      user2
    3      user3
    4      user3
    5      user4


    ID ProjectID
    1    1
    2    1
    3    3
    4    2
    5    2
    6    1

    So from the above user1 has three tasks, user2 has two and user3 has one task while user4 has none. How would I go about creating this as a LINQ query?

    Thanks in advance

    Monday, November 28, 2016 1:46 PM

All replies