你能帮我解决这个错误吗?
Cannot access a disposed object.
Object name: 'DataContext accessed after Dispose.'.
在我的GUI中
private void InitializePage()
{
cbCategory.DataSource = stock.StockCategory.Get();
}
Run Code Online (Sandbox Code Playgroud)
在Datamodel
public IEnumerable<StockCategory> Get()
{
using (leDataContext db = new leDataContext())
{
try
{
var r = from s in db.StockCategories
select s;
return r;
}
catch (Exception ex)
{
Logger.Error(typeof(StockCategory), ex.ToString());
throw;
}
}
}
Run Code Online (Sandbox Code Playgroud)