1.我的存储库类中有这个方法
public class VariablesRepository : IVariablesRepository
{
readonly DBContextClass _context = DBContextClass.Current;
public Variables Find(string name)
{
return _context.Variables.FirstOrDefault(c => c.Name.ToLower().Equals(name.ToLower())) ?? new Variables();
}
}
2.我也有这个静态类
public class Defaults {
private static VariablesRepository _variablesRepository;
static Defaults() {
_variablesRepository = new VariablesRepository();
}
public class MOSScheduleTypes
{
private static int _tryValue;
public static readonly int OneTime = int.TryParse(_variablesRepository.Find("MOSScheduleTypes.OneTime").Value, out _tryValue)
? _tryValue
: 1;
}
}
3.现在如果我在代码中的某个地方这样做:例如
if(someValue == Defaults.MOSScheduleTypes.OneTime)
{
//some code here....
}
我收到错误:操作无法完成,因为 DbContext 已被释放