简体   繁体   English

C# Linq 查询返回部分列值

[英]C# Linq query to return part of column value

I am getting an OutOfMemoryException and I believe it is because the database column that holds the data I want to extract from the database is too large.我收到 OutOfMemoryException 异常,我相信这是因为包含我想从数据库中提取的数据的数据库列太大。 Is there a way I can only retrieve the first X number of characters from a column?有没有办法只能从列中检索前 X 个字符? IE, read the first X characters, write to file, read next X characters until end of column, while saving to a file? IE,读取前 X 个字符,写入文件,读取下 X 个字符直到列结束,同时保存到文件?

This column holds XML data and I want to transfer the XML stored to a text file.此列包含 XML 数据,我想将存储的 XML 传输到文本文件。

Update更新

Answering questions posted below:回答下面发布的问题:

Here is the Linq query where the OutOfMemoryException is thrown:这是抛出 OutOfMemoryException 的 Linq 查询:

                  var output = db.ReportOutputs
                      .Where(i => i.ReportOutputId == rptoId)

                      .Select(i => new
                      {
                          i.ReportRun.ReportRunId,
                          //i.ReportOutputXml.ToString().Substring(1, 100),
                          i.ReportOutputXml,
                      }).FirstOrDefault();

Addressing @bradbury9, the ReportOutputXml is where the XML is stored in the report run table.针对@bradbury9,ReportOutputXml 是 XML 存储在报告运行表中的位置。

Thanks everyone for the ideas.谢谢大家的想法。

What seems to be the issue in the version of DB2 that I have been using.我一直在使用的 DB2 版本中似乎存在什么问题。 I tried the query in my instance of Toad for DB2 and got the same error when double clicking on the data column in the dataset to return that particular column value.我在我的 Toad for DB2 实例中尝试了查询,并在双击数据集中的数据列以返回该特定列值时遇到了相同的错误。

It seems my copy of Toad for DB2 4.0.1.921 is a Freeware version.看来我的 Toad for DB2 4.0.1.921 副本是免费软件版本。 I went on the Quest site and got a new copy of DB2 and did not notice I clicked on the FULL version, 30 day trial.我访问了 Quest 站点并获得了 DB2 的新副本,但没有注意到我点击了完整版,30 天试用版。 I do not get the OutOfMemoryException using the Toad for IBM DB2 7.0.7.106 (non-freeware version).我没有使用 Toad for IBM DB2 7.0.7.106(非免费软件版本)获得 OutOfMemoryException。

This OutOfMemoryException could be a DB2 issue between Freeware and the Full version or a difference between DB2 4 and DB2 7. Or there could be a setting in Toad for DB2 4.0.1.921 that I am not finding.这个 OutOfMemoryException 可能是免费软件和完整版之间的 DB2 问题,或者是 DB2 4 和 DB2 7 之间的差异。或者可能在 Toad 中存在我没有找到的 DB2 4.0.1.921 设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM