How to perform a Linq2Sql query on the following dataset

Posted by Bas on Stack Overflow See other posts from Stack Overflow or by Bas
Published on 2010-05-11T12:44:22Z Indexed on 2010/05/11 12:54 UTC
Read the original article Hit count: 470

Filed under:
|
|
|

I have the following tables:

Person(Id, FirstName, LastName)
{
    (1, "John", "Doe"),
    (2, "Peter", "Svendson")
    (3, "Ola", "Hansen")
    (4, "Mary", "Pettersen")
}

Sports(Id, Name)
{
    (1, "Tennis")
    (2, "Soccer")
    (3, "Hockey")
}

SportsPerPerson(Id, PersonId, SportsId)
{
    (1, 1, 1)
    (2, 1, 3)
    (3, 2, 2)
    (4, 2, 3)
    (5, 3, 2)
    (6, 4, 1)
    (7, 4, 2)
    (8, 4, 3)
}

Looking at the tables, we can conclude the following facts:
John plays Tennis
John plays Hockey
Peter plays Soccer
Peter plays Hockey
Ola plays Soccer
Mary plays Tennis
Mary plays Soccer
Mary plays Hockey

Now I would like to create a Linq2Sql query which retrieves the following:
Get all Persons who play Hockey and Soccer

Executing the query should return: Peter and Mary
Anyone has any idea's on how to approach this in Linq2Sql?

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#