Linq System.OutofMemoryException

时间:2015-09-20 15:33:14

标签: c# sql linq memory database-performance

我在C#中有一个长时间运行的进程,可以在10到200次的任何地方访问Sql表。当进程超过大约50次命中并且每次从同一个表中查询大于大约100,000行时,它将在此行引发系统内存异常,特别是在它将IQuery对象转换为List的底部:

var cht = from p in _db.TickerData
          where p.Time >= Convert.ToDateTime(start) &&
          p.Time <= Convert.ToDateTime(end)
          orderby p.Time
          select p;

_prices = cht.ToList();    < this is where the System.OutofMemoryException occurs >

如何防止此错误?

1 个答案:

答案 0 :(得分:0)

我做了什么我只是让它返回一个IQueryable对象。它仍然是一个列表,但它的表现要好得多。

相关问题