title: How to avoid "There is already an open DataReader associated with this Connection which must be closed first." in MySql/net connector?
body: <p>I have this following piece of code:</p>
  
  <pre><code>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 =&gt; m.Timestamp,
                  m =&gt; (from j in dataContext.TrendSignalRecords
                        where j.TrendRecord_ID == m.ID
                        select j).ToDictionary(p =&gt; p.TrendSignalSetting.Name,
                  p =&gt; (double?)p.Value))
          };
      }
  </code></pre>
  
  <p>But I always get the following exception: </p>
  
  <blockquote>
    <p>There is already an open DataReader
    associated with this Connection which
    must be closed first.</p>
  </blockquote>
  
  <p>Here is the stack trace:</p>
  
  <blockquote>
    <p>[MySqlException (0x80004005): There is
    already an open DataReader associated
    with this Connection which must be
    closed first.]<br>
    MySql.Data.MySqlClient.MySqlCommand.CheckState()
    +237    MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior
    behavior) +146<br>
    MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior
    behavior) +47<br>
    System.Data.Common.DbCommand.ExecuteReader(CommandBehavior
    behavior) +10<br>
    System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
    entityCommand, CommandBehavior
    behavior) +443</p>
    
    <p>[EntityCommandExecutionException: An
    error occurred while executing the
    command definition. See the inner
    exception for details.]<br>
    System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
    entityCommand, CommandBehavior
    behavior) +479<br>
    System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext
    context, ObjectParameterCollection
    parameterValues) +736<br>
    System.Data.Objects.ObjectQuery<code>1.GetResults(Nullable</code>1
    forMergeOption) +149<br>
    System.Data.Objects.ObjectQuery<code>1.Execute(MergeOption
    mergeOption) +31<br>
    System.Data.Objects.DataClasses.EntityReference</code>1.Load(MergeOption
    mergeOption) +148<br>
    System.Data.Objects.DataClasses.RelatedEnd.Load()
    +37    System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
    +8032198    System.Data.Objects.DataClasses.EntityReference<code>1.get_Value()
    +12    Nebula.Models.TrendSignalRecord.get_TrendSignalSetting()
    in C:\Users\Bruno
    Leonardo\documents\visual studio
    2010\Projects\Nebula\Nebula\Models\SmgerDataModel.Designer.cs:2528
    Nebula.Models.Trends.TrendRepository.&lt;GetTimestampedRowStorage&gt;b__b(TrendSignalRecord
    p) in C:\Users\Bruno
    Leonardo\documents\visual studio
    2010\Projects\Nebula\Nebula\Models\Trends\TrendRepository.cs:229
    System.Linq.Enumerable.ToDictionary(IEnumerable</code>1
    source, Func<code>2 keySelector, Func</code>2
    elementSelector, IEqualityComparer<code>1
    comparer) +226<br>
    System.Linq.Enumerable.ToDictionary(IEnumerable</code>1
    source, Func<code>2 keySelector, Func</code>2
    elementSelector) +54<br>
    Nebula.Models.Trends.TrendRepository.b__a(TrendRecord
    m) in C:\Users\Bruno
    Leonardo\documents\visual studio
    2010\Projects\Nebula\Nebula\Models\Trends\TrendRepository.cs:227
    System.Linq.Enumerable.ToDictionary(IEnumerable<code>1
    source, Func</code>2 keySelector, Func<code>2
    elementSelector, IEqualityComparer</code>1
    comparer) +240<br>
    System.Linq.Enumerable.ToDictionary(IEnumerable<code>1
    source, Func</code>2 keySelector, Func<code>2
    elementSelector) +53<br>
    Nebula.Models.Trends.TrendRepository.GetTimestampedRowStorage(String
    startTime, String endTime, Int64
    trendSettingID, Nullable</code>1 period) in
    C:\Users\Bruno
    Leonardo\documents\visual studio
    2010\Projects\Nebula\Nebula\Models\Trends\TrendRepository.cs:224
    Nebula.Models.Trends.TrendRepository.GetTrendSettingContainer(String
    startTime, String endTime, Int64
    unitID, Int64 plantID, Int64
    trendSettingID, GridSortOptions
    gridSortOptions, Nullable<code>1 page,
    Nullable</code>1 recordsPerPage, Nullable<code>1
    period, Int64[] trends, Nullable</code>1
    allTrends) in C:\Users\Bruno
    Leonardo\documents\visual studio
    2010\Projects\Nebula\Nebula\Models\Trends\TrendRepository.cs:206
    Nebula.Controllers.GeneratingUnitController.TrendSettings(Int64
    id, Int64 plantID, Int64
    trendSettingID, String startTime,
    String endTime, Nullable<code>1 page,
    Nullable</code>1 recordsPerPage,
    GridSortOptions options, Nullable<code>1
    period, Int64[] trends, Nullable</code>1
    allTrends) in C:\Users\Bruno
    Leonardo\documents\visual studio
    2010\Projects\Nebula\Nebula\Controllers\GeneratingUnitController.cs:148
    lambda_method(Closure , ControllerBase
    , Object[] ) +543</p>
  </blockquote>
  
  <p>Can you guys help me out?</p>