There is already an open DataReader associated with this Command which must be closed first

前端 未结 18 2291
孤街浪徒
孤街浪徒 2020-11-22 01:40

I have this query and I get the error in this function:

var accounts = from account in context.Accounts
               from guranteer in account.Gurantors
           


        
18条回答
  •  你的背包
    2020-11-22 02:28

    In my case, I had opened a query from data context, like

        Dim stores = DataContext.Stores _
            .Where(Function(d) filter.Contains(d.code)) _
    

    ... and then subsequently queried the same...

        Dim stores = DataContext.Stores _
            .Where(Function(d) filter.Contains(d.code)).ToList
    

    Adding the .ToList to the first resolved my issue. I think it makes sense to wrap this in a property like:

    Public ReadOnly Property Stores As List(Of Store)
        Get
            If _stores Is Nothing Then
                _stores = DataContext.Stores _
                    .Where(Function(d) Filters.Contains(d.code)).ToList
            End If
            Return _stores
        End Get
    End Property
    

    Where _stores is a private variable, and Filters is also a readonly property that reads from AppSettings.

提交回复
热议问题