2013-03-28 52 views
0

我有一個獲得所有產品從我的數據庫代碼:EntityCommandExecutionException occures

using (var entities = new DataEntities()) 
     { 
      var products = entities.Products.AsQueryable(); 
      if (!string.IsNullOrEmpty(nameFilter)) 
      { 
       products = products.Where(o => o.Name.Contains(nameFilter)); 
      } 
      var result = products.Select(ProductBuilder.CreateProductDto); 
      return result.ToList(); 
     } 

CreateProductDto方法:

 public static ProductDto CreateProductDto(this Product product) 
    { 
     return new ProductDto 
     { 
      Id = product.Id, 
      Name = product.Name, 
      IsEnabled = product.IsEnabled, 
      KeyPairDto = new KeyPairDto() 
      { 
       Id = product.KeyPair.Id, 
       EncryptedPrivateExponent = product.KeyPair.EncryptedPrivateExponent, 
       Modulus = product.KeyPair.Modulus, 
       PublicExponent = product.KeyPair.PublicExponent, 
      }, 
     }; 
    } 

它的工作原理我colleaugue機器上的罰款。但是我得到EntityCommandExecutionException與下面的內部異常:已經有一個打開的DataReader與此命令關聯,必須先關閉它。當試圖訪問product.KeyPair

有趣的是,如果我通過調試器刷新product.KeyPair - 它加載正常。

回答

1

添加

MultipleActiveResultSets=true 

連接字符串的供應部件的實體框架的連接字符串中(即部分定義了數據源,初始目錄等)

+0

非常感謝您! – Zharro 2013-03-28 08:48:53

相關問題