none
Master Detail Query RRS feed

  • Question

  • Hi there:

    I'm working with VS2012, DBContext, and SQL Server 2012 express

    Suppose I have two related ADO NET Entity Tables Categories and Products:

    I need a LINQ to SQL query that returns a result set containing all Categories with their corresponding Products. Something like:

    It would be great if its a smart query, like a subquery or join

    I'd like to bind it to a wpf data control

    Thank you in advance.

    Rafael


    Believe you can do it, and you will!!




    • Edited by RalphDev Wednesday, January 22, 2014 3:30 PM
    Wednesday, January 22, 2014 12:34 PM

Answers

  • Hi RalphDev;

    The following query when executed will return all Categories with there related Products.

    var results = (from c in Categories.Include("Products")
                   select c).ToList();

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by RalphDev Wednesday, January 22, 2014 4:20 PM
    Wednesday, January 22, 2014 3:54 PM

All replies

  • Hi RalphDev;

    The following query when executed will return all Categories with there related Products.

    var results = (from c in Categories.Include("Products")
                   select c).ToList();

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by RalphDev Wednesday, January 22, 2014 4:20 PM
    Wednesday, January 22, 2014 3:54 PM
  • Thank you

    How do I Mark as Helpful?


    Believe you can do it, and you will!!


    • Edited by RalphDev Wednesday, January 22, 2014 4:22 PM
    Wednesday, January 22, 2014 4:22 PM
  • Thanks;

    In my post you will see a blue box with a check mark. Right under it you will see an up would pointing gray arrow, click on the arrow.

    Have a great day.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, January 22, 2014 4:26 PM