Warm tip: This article is reproduced from stackoverflow.com, please click
asp.net-core-2.0 c#

LINQ Join Throws An Error Saying "There is already an open DataReader associated with this Command w

发布于 2020-04-18 09:45:10

I have a Linq join and have populated viewmodel using that join. On running, there is an error on that join saying

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

Below is my join

public List<GallerySisterComanyVM> GetAllGallery()
{
    var list = (from GI in uow.Repository<GalleryImage>().GetAll()
        join SC in uow.Repository<SisterCompany>().GetAll() on GI.SisterCompanyId equals SC.SisterCompanyId
        select new GallerySisterComanyVM
        {
            GalleryImageId=GI.GalleryImageId,
            Status=GI.Status,
            Image=GI.Image,
            SisterCompanyName=SC.SisterCompanyName
    }).OrderByDescending(x=>x.GalleryImageId).ToList();

    return list;
}
Questioner
Alfa Group
Viewed
29
Tom Ruyter 2020-02-04 22:48

Check your web.config or .json secrets configuration file for the SQL connection string used to start the Context and look for the "MultipleActiveResultSets=True" bit.

If this doesn't exist, try adding it to the end of your SQL string and try again.

See here for details