错误如下图
使用方法:
在单例模式下调用同一个方法NewsContents
public readonly DataContext DC;
public MyMethods()
{
DC = new DataContext("***",
DBTypeEnum.MySql);
}
public IEnumerable<Content> NewsContents()
{
return DC.Set<Content>().Where(p => p.TemplateCode == AppConsts.News);
}
程序部署后经常性的报错A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext
请问改如何使用或实现方法,目的为查询出一个表的数据后可多次复用
感谢回答,目前采用的方法是在实例化时直击查询数据,如下
速度有了很大提升,也不再报错了