3

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 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.