0

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;
}
Taazar
  • 1,545
  • 18
  • 27

2 Answers2

0

Assume it is due to the first repository query still running when the second is called. How about querying the context directly instead of the repository, or create the joined query in the repository as a separate method?

JMP
  • 1,864
  • 2
  • 8
  • 16
0

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

Tom Ruyter
  • 176
  • 2
  • 9