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

前端 未结 18 2288
孤街浪徒
孤街浪徒 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:10

    This can happen if you execute a query while iterating over the results from another query. It is not clear from your example where this happens because the example is not complete.

    One thing that can cause this is lazy loading triggered when iterating over the results of some query.

    This can be easily solved by allowing MARS in your connection string. Add MultipleActiveResultSets=true to the provider part of your connection string (where Data Source, Initial Catalog, etc. are specified).

提交回复
热议问题