产生非常大的XML文件使用LINQ到XML和LINQ到SQL非常大、文件、SQL、XML

2023-09-05 02:36:29 作者:8.青瓷清茶倾城歌

我试图做一个转储到一个非常大的数据库(许多千兆字节)的XML。我使用LINQ到SQL来获取数据的数据库和LINQ到XML生成XML。我使用 XStreamingElement 来保持内存使用的低。这项工作仍在然而,分配所有可用内存,基林比没有写过任何XML之前。其结构是这样的:

I'm trying to do a dump to XML of a very large database (many gigabytes). I'm using Linq-to-SQL to get the data out of the database and Linq-to-XML to generate XML. I'm using XStreamingElement to keep memory use low. The job still allocates all available memory, however, before keeling over without having written any XML. The structure looks like this:

var foo =
    new XStreamingElement("contracts",
       <LinqtoSQL which fetches data>.Select(d =>
    new XElement("contract",
        ... generate attributes etc...
using (StreamWriter sw = new StreamWriter("contracts.xml"))
{
    using (XmlWriter xw = XmlWriter.Create(sw))
    {
        foo.WriteTo(xw);
    }
}

我也试着与节能:

I've also tried saving with:

foo.Save("contracts.xml", SaveOptions.DisableFormatting);

......无济于事。

...to no avail.

任何线索?

推荐答案

右键,解决被分块我的数据成组的10,000项,写他们单独的XML文件中的问题。再想一想其他的数据交换格式,并购买更大的服务器。

Right, "solved" the problem by chunking my data into sets of 10,000 items and writing them to separate XML files. Will ponder other data exchange format and buy a larger server.

我仍然会强大有趣的,如果有人想出如何正确利用 XStreamingElement

I would still be mighty interesting if someone had figured out how to properly take advantage of XStreamingElement.