'((new System.Collections.Generic.Mscorlib_CollectionDebugViewthrew类型'System.ObjectDisposedException'的异常'

时间:2017-03-15 17:06:14

标签: c# sql asp.net-mvc entity-framework

这是我的代码我有功能

public List<Questions_tbl> GetQuestions()
        {
  using (Question_answerEntities dc = new Question_answerEntities())
                    {
                        return dc.Questions_tbl.ToList();
                    }
}

我从另一个人那里调用这个函数

  public string GetquestList()
        {        
            var list = NC.GetQuestions();   
        }

问题表包含答案表的列表 enter image description here 并看到此异常

Answer_tbl = '((new System.Collections.Generic.Mscorlib_CollectionDebugView<Question_Answer_App_Task.Models.Questions_tbl>(list)).Items[0]).Answer_tbl' threw an exception of type 'System.ObjectDisposedException'

这是我的班级

 public partial class Questions_tbl
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Questions_tbl()
        {
            this.Answer_tbl = new HashSet<Answer_tbl>();
        }

        public long Quest_Id { get; set; }
        public string Quest_Body { get; set; }
        public long User_Id { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<Answer_tbl> Answer_tbl { get; set; }
        public virtual User_tbl User_tbl { get; set; }
    }

0 个答案:

没有答案