我在 MySQL 数据库中有一些表来表示来自传感器的记录。我正在开发的系统的功能之一是将数据库中的这些记录显示给网络用户,所以我使用 ADO.NET 实体数据模型创建一个 ORM,使用 Linq to SQL 从数据库中获取数据,并将它们存储在我设计的 ViewModel 中,因此我可以使用 MVCContrib Grid Helper 显示它:
public IQueryable<TrendSignalRecord> GetTrends()
{
var dataContext = new SmgerEntities();
var trendSignalRecords = from e in dataContext.TrendSignalRecords
select e;
return trendSignalRecords;
}
public IQueryable<TrendRecordViewModel> GetTrendsProjected()
{
var projectedTrendRecords = from t in GetTrends()
select new TrendRecordViewModel
{
TrendID = t.ID,
TrendName = t.TrendSignalSetting.Name,
GeneratingUnitID = t.TrendSignalSetting.TrendSetting.GeneratingUnit_ID,
//{...}
Unit = t.TrendSignalSetting.Unit
};
return projectedTrendRecords;
}
我调用 GetTrendsProjectedMethod,然后使用 Linq to SQL 仅选择我想要的记录。它在我的开发场景中运行良好,但是当我在真实场景中测试它时,记录数量更多(大约一百万条记录),它停止工作。
我放了一些调试消息来测试它,一切正常,但是当它到达return View()
语句时,它只是停止,向我抛出 MySQLException: Timeout expired
。这让我想知道我发送到页面的数据是否由页面本身检索(它仅在页面本身需要时搜索数据库中显示的项目,或类似的东西)。
我所有的其他页面都使用相同的工具集:MVCContrib Grid Helper、ADO.NET、Linq to SQL、MySQL,其他一切都正常。