locked
Get Records RRS feed

  • Question

  • Hello,

    I three tables: Posts, Tags and PostsTags that relates Posts to Tags.

    I added the tables to EF and I see Posts and Tags tables and the relationship as expected.

    How can I get all posts and their Tags using linq?
    Do I need to create a join or by getting the Posts the Tags are filled automatically?

    Thanks,
    Miguel
    Tuesday, August 4, 2009 5:05 PM

Answers

  • Hi Miguel,

    If your associations and navigation properties are configured correctly, you just need to use the Include clause in your LINQ query, something like:

    var records = dbContext.Posts.Include("Tags"); //assuming that your entity name is 'Posts' and the navigation property is 'Tags'
    //consume records (or apply more filters )
    
    Hope that helps,

    Regards,

    Syed Mehroz Alam
    My Blog | My Articles
    • Edited by Syed Mehroz Alam Tuesday, August 4, 2009 5:57 PM included link to msdn
    • Proposed as answer by Syed Mehroz Alam Friday, August 7, 2009 5:42 AM
    • Marked as answer by Yichun_Feng Tuesday, August 11, 2009 1:20 AM
    Tuesday, August 4, 2009 5:54 PM