我有以下这段代码:
public TimestampedRowStorage GetTimestampedRowStorage(string startTime, string endTime, long trendSettingID, int? period)
{
var timestampedList = (from t in dataContext.TrendRecords
where t.TrendSetting_ID == trendSettingID
select t).ToList();
return new TimestampedRowStorage
{
TimestampedDictionary = timestampedList.ToDictionary(m => m.Timestamp,
m => (from j in dataContext.TrendSignalRecords
where j.TrendRecord_ID == m.ID
select j).ToDictionary(p => p.TrendSignalSetting.Name,
p => (double?)p.Value))
};
}
但是我总是得到以下异常:
这是堆栈跟踪:
你们能帮我吗?
最佳答案
该错误可能是因为您在访问数据库时尝试访问数据库。
您应该尝试将两个Linq表达式分开。
也许这样写:
var TimestampedList = (from t in dataContext.TrendRecords
where t.TrendSetting_ID == trendSettingID
select t).ToList();
TimestampedDictionary = timestampedList.ToDictionary(m => m.Timestamp,
m => (from j in dataContext.TrendSignalRecords
where j.TrendRecord_ID == m.ID
select j).ToDictionary(p => p.TrendSignalSetting.Name,
p => (double?)p.Value))
关于c# - 如何避免MySql/net连接器中的 "There is already an open DataReader associated with this Connection which must be closed first."?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6271971/