我从该服务获取产品图片时在版本 3.8 中遇到此错误:
var defaultProductPicture=_pictureService.GetPicturesByProductId(productmodel.Id,1).FirstOrDefault();
productmodel.productImagUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true);
我的GetPicturesByProductId
服务是:
public virtual IList<Picture> GetPicturesByProductId(int productId, int recordsToReturn = 0)
{
if (productId == 0)
return new List<Picture>();
var query = from p in _pictureRepository.Table
join pp in _productPictureRepository.Table on p.Id equals pp.PictureId
orderby pp.DisplayOrder
where pp.ProductId == productId
select p;
if (recordsToReturn > 0)
query = query.Take(recordsToReturn);
var pics = query.ToList();
return pics;
}
我不知道为什么 GetPictureByProductId
在较新版本 3.8 中会遇到此错误。在 3.7 版本中一切正常。
最佳答案
如果您在迭代另一个查询的结果时执行查询,则可能会发生这种情况。
因此,只需将 MultipleActiveResultSets=True
添加到 setting.txt
文件中的连接字符串即可。
希望这有帮助!
关于c# - 已存在与此命令关联的打开的 DataReader,必须先将其关闭 在 Nopcommerce 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39826260/