Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 284249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:26:32+00:00 2026-05-12T05:26:32+00:00

The only thing I can find when dealing with master/detail and LINQ is through

  • 0

The only thing I can find when dealing with master/detail and LINQ is through databinding. However, I am using LINQ to query my data and will need to manually loop through results without the need for databinding. My final intent is to loop through a master result set, get a grouped list of children, and output the master/detail data as a hierchial structure in XML.

My illustration: I have a table called my_master_tbl and and it will be queried by a date. I have a child table called my_child_tbl which will be grouped by date, by the master id, and use sum() to total some fields. I’d like to link the grouped data to the master and loop through the master/detail in the most efficient way possible to export the results as xml. What is that way? The only way I can think of is to loop through the master, then query the grouped result set of the children based on master_id.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:26:32+00:00Added an answer on May 12, 2026 at 5:26 am

    I would implement this using a combination of LinqToSql and LinqToXml, similar to the following:

    var query = new XDocument(
        new XElement("Results", from i in context.my_master_tbl
                                where i.ItemDate > DateTime.Now.AddDays(-7)
                                select new XElement("MasterItem",
                                    new XAttribute("MasterName", i.Name),
                                     from c in i.my_child_tbl
                                     group c by c.Date into g
                                     select new XElement("Child",
                                         new XAttribute("Date", g.Key),
                                         new XAttribute("SumField", g.Sum(d => d.FieldToSum))
                                     )
                                )));
    

    Here is some resulting Xml this will generate:

    <Results>
     <MasterItem MasterName="A">
      <Child Date="2009-01-15T00:00:00-06:00" SumField="491470" />
     </MasterItem>
     <MasterItem MasterName="B">
      <Child Date="2009-01-29T00:00:00-06:00" SumField="491526" />
     </MasterItem>
     <MasterItem MasterName="C">
      <Child Date="2009-01-15T00:00:00-06:00" SumField="1965960" />
      <Child Date="2009-07-14T00:00:00-05:00" SumField="-27" />
     </MasterItem>
     <MasterItem MasterName="D" />
     <MasterItem MasterName="E" />
    </Results>
    

    I’m sure you’ll need to make a few changes to this based on the layout you were planning on using, but hopefully it will give you some ideas.

    This also assumes your relationships are setup between your master and child tables. If they aren’t, a few other changes will be necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a image generator but the only thing I can find
I can only think of a client-side solution using jQuery, but is it possible
i'm using FAYE and rails application and the only thing tha annoys me very
The only place I can think to change is the version in my Target
Disclaimer: I'm not a c++ developer, I can only do basic things. (I understand
the only thing i know about this subject is... in PHP 5, when a
Been searching but the only thing I found was http://evain.net/blog/articles/2009/07/30/rebasing-system-reactive-to-the-net-clr which I got to
I need to get information on variables and the only thing I have is
I have to ask this, because: The only thing I recognize is, that if
I got this comma separated file with a bunch of numbers The only thing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.