tags:

views:

24

answers:

1

Im using linq to sql

i have a Documents table

and a FavouriteDocuments table

FavouriteDocuments table has a documentsID fk and a ProjectID fk.

given the ProjectID how do i get all the documents(from the documents table) that are a FavouriteDocument for that particular project.

thanks

+1  A: 

Try this:

public static Document[] GetFavouriteDocumentsForProject(int projectId)
{
    using (var db = new MyContext())
    {
        return
            (from favourite in db.FavouriteDocuments
            where favourite.ProjectID == projectId
            select favourite.Document).ToArray();
    }
}

I hope this helps.

Steven