using
次のコードは、コメント アウトされたステートメントを使用しない限り機能します。私が使うとき、私はusing
得るThe operation cannot be completed because the DbContext has been disposed
public IQueryable<DTOs.FormQuestionDTO> GetForm(int id, int page = 0)
{
// FS stores pages starting with 1
page = page == 0 ? 1 : page;
//using (var db = new Models.FormEntities())
//{
var db = new Models.FormEntities();
var questions = from fq in db.FormQuestions
join q in db.Questions on fq.QuestionId equals q.QuestionId
where (fq.FormId == id) && (fq.PageNumber == page) && fq.Disabled == false
orderby fq.DisplayOrder
select new { q.QuestionId, q.QuestionText, fq.DisplayOrder, fq.PageNumber };
var dto = questions.Project().To<DTOs.FormQuestionDTO>();
if (questions == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
else
{
return dto;
}
//}
}
DbContext
私の最初の予感は、LINQクエリの直後にUsingが破棄されているということでしたが、ブロックの.Dipose()
中に入れたときに同じエラーが発生しました。finally
何が起きてる?私はしばらく C# を使っていないので、単純なものが欠けている可能性があります。