我使用ExecuteStoreQuery
并IEnumerable<>
列出清单。当我使用 foreach 获取此列表并在该区域使用一些 linq 查询时,它会出现此错误:
已经有一个打开的 DataReader 与此 Connection 关联,必须先关闭它。
我必须为此做些什么?
我的代码如下所示:
//IEnumerable function
public IEnumerable<NewTable> YirmiAjansTweetList()
{
string nativeSQLQuery = "Select t1.id,t1.baslik,t1.url,t1.gtarih,t3.ck,t3.cs,t2.token,t2.tokensecret from yirmiajanstweets t1 join uyeler t2 ON(t1.uid=t2.u_id) join uygulamalar t3 ON(t2.uyid=t3.u_id) where t1.gtarih is not null and t1.durum=0 and t1.gtarih<Now();";
IEnumerable<NewTable> newList = db.ExecuteStoreQuery<NewTable>(nativeSQLQuery, System.Data.Objects.MergeOption.NoTracking);
if (newList != null)
{
return newList;
}
else
{
return null;
}
}
public class NewTable
{
public int id { get; set; }
public string baslik { get; set; }
public string url { get; set; }
public DateTime gtarih { get; set; }
public string ck { get; set; }
public string cs { get; set; }
public string token { get; set; }
public string tokensecret { get; set; }
}
//look for a record function
public yirmiajanstweets YirmiAjansKayitBak(int _id)
{
yirmiajanstweets ya = db.yirmiajanstweets.FirstOrDefault(f => f.id == _id);
if (ya != null)
{
return ya;
}
else
{
return null;
}
}
//i get this list like that with foreach
IEnumerable<dynamic> ya = yaBLL.YirmiAjansTweetList().AsEnumerable();
if (ya != null)
{
foreach (var item in ya)
{
//when read this line give error
var myRecord = YirmiAjansKayitBak(item.id);
}
}
else
{
Response.Write("Not found !");
}