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 6682525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:42:59+00:00 2026-05-26T04:42:59+00:00

I have built an application that generates a large XML file using Linq-to-Entities and

  • 0

I have built an application that generates a large XML file using Linq-to-Entities and XElement. It takes a whole core of our 2GHz server for about half an hour and uses ~1GB of memory.

I’m doing the following type of work:

var xml = from x in dbContext.Table1
          select new XElement("Table1",
                     new XElement("Field1", x.Field1),
                     new XElement("Field2", x.Field2),
                     new XElement("Field3", x.Field3),
                     new XElement("MoreFields",
                         new XElement("FieldA", x.MoreFields.FieldA),
                         new XElement("FieldA", x.MoreFields.FieldA),
                         new XElement("FieldA", x.MoreFields.FieldA.DoSomeWorkWithThisField())
    )
);

I have another level of depth or two and several of the fields have work done like parsing an int out of a string using RegEx.Match()

Does anyone have any optimization or refactoring recommendations? I tried using XStreamingElement but it didn’t seem to make any difference.

  • 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-26T04:43:00+00:00Added an answer on May 26, 2026 at 4:43 am

    It looks like you’re fetching the whole of Table1 multiple times.

    Can you fetch it to a List<T> and then use that repeatedly?

    var list = dbContext.Table1.ToList();
    var xml = new XElement("Table1",
        new XElement("Field1", list.Field1),
        new XElement("Field2", list.Field2),
        new XElement("Field3", list.Field3),
        new XElement("MoreFields",
            new XElement("FieldA", list.MoreFields.FieldA),
            new XElement("FieldA", list.MoreFields.FieldA),
            new XElement("FieldA", list.MoreFields.FieldA.DoSomeWorkWithThisField())
        )
    );
    

    I suspect there’s rather more involved than this, but basically – fetch what you need into memory up-front, and then work from that. If you only need to use an item of data once, that’s fine to do only when you need it – but avoid pulling the same data time and time again.

    How big is the document you’re generating, and how much memory does your machine have? You might want to try looking at the performance counters – it’s possible that you’re spending most of the time garbage collecting.

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

Sidebar

Related Questions

I have built a web application using Java EE platform that sells one of
I'm using a custom-built inhouse application that generates a standard set of reports on
I have built an application that uses SQL Express 2005 and I want to
We have built a web application that accepts SOAP messages, does some processing, calls
I have built a Java application that has some dependencies (~10). I would like
I have built an application in C# that I would like to be optimized
I have built a windows C++ application that I'd like to port to linux.
I have built a MS Access 2007 application that can create reports files in
I have an already built application and I want to add a feature that
I have an application that is built against OpenSceneGraph (2.6.1) and therefore indirectly OpenGL.

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.