1

使っExecuteStoreQueryIEnumerable<>一覧にしてます。foreach でこのリストを取得し、この領域でいくつかの linq クエリを使用すると、次のエラーが発生します。

この接続に関連付けられている開いている DataReader が既に存在し、最初に閉じる必要があります。

このために私は何をしなければなりませんか?

私のコードは次のようになります:

//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 !");
}
4

2 に答える 2

0

コレクションを反復処理する前に、クエリ結果をリストにロードしてみてください。

IEnumerable<dynamic> ya = yaBLL.YirmiAjansTweetList().ToList();
于 2013-06-25T16:00:28.037 に答える