Asp.net mvc 2 序列化对象时检测到循环引用。这个错误到底是什么?

Asp.net mvc 2 序列化对象时检测到循环引用。这个错误到底是什么?,asp.net-mvc-2,serialization,Asp.net Mvc 2,Serialization,我想将列表对象序列化为JSON数据 我当前在ASP.NET MVC应用程序中使用的代码是: List<Question> questionList; questionList = questionManager.GetquestionsByTestId(id); var listData = questionList.ToArray(); JavaScriptSerializer seri

我想将
列表
对象序列化为JSON数据

我当前在ASP.NET MVC应用程序中使用的代码是:

List<Question> questionList;            
            questionList = questionManager.GetquestionsByTestId(id);
            var listData = questionList.ToArray();
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            string strData = serializer.Serialize(listData);

            JsonResult json = Json(strData, JsonRequestBehavior.AllowGet);
这个错误意味着什么

编辑:问题类

public partial class Question : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _QuestionId;

        private string _QuestionText;

        private System.Nullable<int> _TopicId;

        private System.Nullable<int> _Marks;

        private System.Nullable<int> _QuestionTypeId;

        private System.Nullable<int> _ChapterId;

        private System.Nullable<int> _Weightage;

        private System.Nullable<System.TimeSpan> _ExpectedTimeToAnswer;

        private EntitySet<Answer> _Answers;

        private EntitySet<TestDetail> _TestDetails;

        private EntityRef<Chapter> _Chapter;

        private EntityRef<QuestionType> _QuestionType;

        private EntityRef<Topic> _Topic;

    #region Extensibility Method Definitions
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnQuestionIdChanging(int value);
    partial void OnQuestionIdChanged();
    partial void OnQuestionTextChanging(string value);
    partial void OnQuestionTextChanged();
    partial void OnTopicIdChanging(System.Nullable<int> value);
    partial void OnTopicIdChanged();
    partial void OnMarksChanging(System.Nullable<int> value);
    partial void OnMarksChanged();
    partial void OnQuestionTypeIdChanging(System.Nullable<int> value);
    partial void OnQuestionTypeIdChanged();
    partial void OnChapterIdChanging(System.Nullable<int> value);
    partial void OnChapterIdChanged();
    partial void OnWeightageChanging(System.Nullable<int> value);
    partial void OnWeightageChanged();
    partial void OnExpectedTimeToAnswerChanging(System.Nullable<System.TimeSpan> value);
    partial void OnExpectedTimeToAnswerChanged();
    #endregion

        public Question()
        {
            this._Answers = new EntitySet<Answer>(new Action<Answer>(this.attach_Answers), new Action<Answer>(this.detach_Answers));
            this._TestDetails = new EntitySet<TestDetail>(new Action<TestDetail>(this.attach_TestDetails), new Action<TestDetail>(this.detach_TestDetails));
            this._Chapter = default(EntityRef<Chapter>);
            this._QuestionType = default(EntityRef<QuestionType>);
            this._Topic = default(EntityRef<Topic>);
            OnCreated();
        }

        [Column(Storage="_QuestionId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
        public int QuestionId
        {
            get
            {
                return this._QuestionId;
            }
            set
            {
                if ((this._QuestionId != value))
                {
                    this.OnQuestionIdChanging(value);
                    this.SendPropertyChanging();
                    this._QuestionId = value;
                    this.SendPropertyChanged("QuestionId");
                    this.OnQuestionIdChanged();
                }
            }
        }

        [Column(Storage="_QuestionText", DbType="NVarChar(MAX)")]
        public string QuestionText
        {
            get
            {
                return this._QuestionText;
            }
            set
            {
                if ((this._QuestionText != value))
                {
                    this.OnQuestionTextChanging(value);
                    this.SendPropertyChanging();
                    this._QuestionText = value;
                    this.SendPropertyChanged("QuestionText");
                    this.OnQuestionTextChanged();
                }
            }
        }

        [Column(Storage="_TopicId", DbType="Int")]
        public System.Nullable<int> TopicId
        {
            get
            {
                return this._TopicId;
            }
            set
            {
                if ((this._TopicId != value))
                {
                    if (this._Topic.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnTopicIdChanging(value);
                    this.SendPropertyChanging();
                    this._TopicId = value;
                    this.SendPropertyChanged("TopicId");
                    this.OnTopicIdChanged();
                }
            }
        }

        [Column(Storage="_Marks", DbType="Int")]
        public System.Nullable<int> Marks
        {
            get
            {
                return this._Marks;
            }
            set
            {
                if ((this._Marks != value))
                {
                    this.OnMarksChanging(value);
                    this.SendPropertyChanging();
                    this._Marks = value;
                    this.SendPropertyChanged("Marks");
                    this.OnMarksChanged();
                }
            }
        }

        [Column(Storage="_QuestionTypeId", DbType="Int")]
        public System.Nullable<int> QuestionTypeId
        {
            get
            {
                return this._QuestionTypeId;
            }
            set
            {
                if ((this._QuestionTypeId != value))
                {
                    if (this._QuestionType.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnQuestionTypeIdChanging(value);
                    this.SendPropertyChanging();
                    this._QuestionTypeId = value;
                    this.SendPropertyChanged("QuestionTypeId");
                    this.OnQuestionTypeIdChanged();
                }
            }
        }

        [Column(Storage="_ChapterId", DbType="Int")]
        public System.Nullable<int> ChapterId
        {
            get
            {
                return this._ChapterId;
            }
            set
            {
                if ((this._ChapterId != value))
                {
                    if (this._Chapter.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnChapterIdChanging(value);
                    this.SendPropertyChanging();
                    this._ChapterId = value;
                    this.SendPropertyChanged("ChapterId");
                    this.OnChapterIdChanged();
                }
            }
        }

        [Column(Storage="_Weightage", DbType="Int")]
        public System.Nullable<int> Weightage
        {
            get
            {
                return this._Weightage;
            }
            set
            {
                if ((this._Weightage != value))
                {
                    this.OnWeightageChanging(value);
                    this.SendPropertyChanging();
                    this._Weightage = value;
                    this.SendPropertyChanged("Weightage");
                    this.OnWeightageChanged();
                }
            }
        }

        [Column(Storage="_ExpectedTimeToAnswer", DbType="Time")]
        public System.Nullable<System.TimeSpan> ExpectedTimeToAnswer
        {
            get
            {
                return this._ExpectedTimeToAnswer;
            }
            set
            {
                if ((this._ExpectedTimeToAnswer != value))
                {
                    this.OnExpectedTimeToAnswerChanging(value);
                    this.SendPropertyChanging();
                    this._ExpectedTimeToAnswer = value;
                    this.SendPropertyChanged("ExpectedTimeToAnswer");
                    this.OnExpectedTimeToAnswerChanged();
                }
            }
        }

        [Association(Name="Question_Answer", Storage="_Answers", ThisKey="QuestionId", OtherKey="QuestionId")]
        public EntitySet<Answer> Answers
        {
            get
            {
                return this._Answers;
            }
            set
            {
                this._Answers.Assign(value);
            }
        }

        [Association(Name="Question_TestDetail", Storage="_TestDetails", ThisKey="QuestionId", OtherKey="QuestionId")]
        public EntitySet<TestDetail> TestDetails
        {
            get
            {
                return this._TestDetails;
            }
            set
            {
                this._TestDetails.Assign(value);
            }
        }

        [Association(Name="Chapter_Question", Storage="_Chapter", ThisKey="ChapterId", OtherKey="ChapterId", IsForeignKey=true)]
        public Chapter Chapter
        {
            get
            {
                return this._Chapter.Entity;
            }
            set
            {
                Chapter previousValue = this._Chapter.Entity;
                if (((previousValue != value) 
                            || (this._Chapter.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Chapter.Entity = null;
                        previousValue.Questions.Remove(this);
                    }
                    this._Chapter.Entity = value;
                    if ((value != null))
                    {
                        value.Questions.Add(this);
                        this._ChapterId = value.ChapterId;
                    }
                    else
                    {
                        this._ChapterId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Chapter");
                }
            }
        }

        [Association(Name="QuestionType_Question", Storage="_QuestionType", ThisKey="QuestionTypeId", OtherKey="QuestionTypeId", IsForeignKey=true)]
        public QuestionType QuestionType
        {
            get
            {
                return this._QuestionType.Entity;
            }
            set
            {
                QuestionType previousValue = this._QuestionType.Entity;
                if (((previousValue != value) 
                            || (this._QuestionType.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._QuestionType.Entity = null;
                        previousValue.Questions.Remove(this);
                    }
                    this._QuestionType.Entity = value;
                    if ((value != null))
                    {
                        value.Questions.Add(this);
                        this._QuestionTypeId = value.QuestionTypeId;
                    }
                    else
                    {
                        this._QuestionTypeId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("QuestionType");
                }
            }
        }

        [Association(Name="Topic_Question", Storage="_Topic", ThisKey="TopicId", OtherKey="TopicId", IsForeignKey=true)]
        public Topic Topic
        {
            get
            {
                return this._Topic.Entity;
            }
            set
            {
                Topic previousValue = this._Topic.Entity;
                if (((previousValue != value) 
                            || (this._Topic.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Topic.Entity = null;
                        previousValue.Questions.Remove(this);
                    }
                    this._Topic.Entity = value;
                    if ((value != null))
                    {
                        value.Questions.Add(this);
                        this._TopicId = value.TopicId;
                    }
                    else
                    {
                        this._TopicId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Topic");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_Answers(Answer entity)
        {
            this.SendPropertyChanging();
            entity.Question = this;
        }

        private void detach_Answers(Answer entity)
        {
            this.SendPropertyChanging();
            entity.Question = null;
        }

        private void attach_TestDetails(TestDetail entity)
        {
            this.SendPropertyChanging();
            entity.Question = this;
        }

        private void detach_TestDetails(TestDetail entity)
        {
            this.SendPropertyChanging();
            entity.Question = null;
        }
    }
公共部分类问题:INotifyPropertyChanged,INotifyPropertyChanged
{
私有静态属性ChangingEventArgs emptyChangingEventArgs=新属性ChangingEventArgs(String.Empty);
私人内部问题ID;
私有字符串(文本);;
私有系统。可为空的_TopicId;
私有系统。可为空的_标记;
私有系统。可为空的_QuestionTypeId;
私有系统。可为空的章;
私有系统。可为空的权重;
专用系统。可为空_ExpectedTimeToAnswer;
私有实体集_;
私有实体集_TestDetails;
私人实体参考章;
私有实体ref_问题类型;
私有实体引用主题;
#区域扩展性方法定义
局部空腔加载();
部分无效OnValidate(System.Data.Linq.ChangeAction);
部分空白一经处理();
问题ID更改时部分无效(int值);
QuestionIDChanged()上的部分无效;
部分无效OnQuestionTextChangeing(字符串值);
部分无效OnQuestionTextChanged();
局部无效OnTopicId更改(System.Nullable值);
局部无效OnTopicIdChanged();
标记上的部分无效(System.Nullable值);
在markschanged()上的部分空白;
QuestionTypeIdChangeing部分无效(System.Nullable值);
QuestionTypeIdChanged()上的部分无效;
部分无效的分格更改(System.Nullable值);
局部空洞onchapteredchanged();
权重更改时部分无效(System.Nullable值);
权重更改时部分无效();
部分无效一个预期的TimeToAnswerChanged(System.Nullable值);
部分无效OneExpectedTimeToAnswerChanged();
#端区
公众问题(
{
this.\u Answers=newentityset(新操作(this.attach\u Answers)、新操作(this.detach\u Answers));
this._TestDetails=newentityset(新操作(this.attach_TestDetails)、新操作(this.detach_TestDetails));
本章=默认值(EntityRef);
此._QuestionType=默认值(EntityRef);
此._Topic=default(EntityRef);
OnCreated();
}
[列(Storage=“\u QuestionId”,AutoSync=AutoSync.OnInsert,DbType=“Int NOT NULL IDENTITY”,IsPrimaryKey=true,IsDbGenerated=true)]
公共int问题ID
{
得到
{
将此返回。\u QuestionId;
}
设置
{
if((此._QuestionId!=值))
{
这是一个正在改变的问题(值);
此参数为.SendPropertyChanging();
这个._QuestionId=值;
此.SendPropertyChanged(“问题ID”);
这个.OnQuestionIdChanged();
}
}
}
[Column(Storage=“\u QuestionText”,DbType=“NVarChar(MAX)”)]
公共字符串文本
{
得到
{
返回此。\u问题文本;
}
设置
{
if((此._QuestionText!=值))
{
此.onQuestionTextChangeing(值);
此参数为.SendPropertyChanging();
这个._QuestionText=值;
此.SendPropertyChanged(“问题文本”);
this.OnQuestionTextChanged();
}
}
}
[Column(Storage=“\u TopicId”,DbType=“Int”)]
公共系统。可为空的TopicId
{
得到
{
把这个还给我;
}
设置
{
如果((此._TopicId!=值))
{
如果(此._主题.hasloadeOrassignedValue)
{
抛出新System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
这是一个改变(值);
此参数为.SendPropertyChanging();
该值为.\u TopicId=值;
此项。SendPropertyChanged(“TopicId”);
this.OnTopicIdChanged();
}
}
}
[Column(Storage=“_Marks”,DbType=“Int”)]
公共系统.可取消的标记
{
得到
{
把这个还给我;
}
设置
{
如果((此._标记!=值))
{
这是一种价值观;
此参数为.SendPropertyChanging();
这个。_标记=值;
此项。SendPropertyChanged(“标记”);
这个。OnMarksChanged();
}
}
}
[Column(Storage=“\u QuestionTypeId”,DbType=“Int”)]
公共系统。可为空的QuestionTypeId
{
得到
{
返回此。\u QuestionTypeId;
}
设置
{
if((this.\u QuestionTypeId!=值))
{
如果(此._QuestionType.HasLoadedOrAssignedValue)
{
抛出新System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
此.onQuestionTypeIdChangeing(值);
此参数为.SendPropertyChanging();
这个.\u QuestionTypeId=值;
此.SendPropertyChanged(“问题类型ID”);
this.OnQuestionTypeIdChanged();
}
}
}
[Column(Storage=“\u ChapterId”,DbType=“Int”)]
公共系统。可为空
public partial class Question : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _QuestionId;

        private string _QuestionText;

        private System.Nullable<int> _TopicId;

        private System.Nullable<int> _Marks;

        private System.Nullable<int> _QuestionTypeId;

        private System.Nullable<int> _ChapterId;

        private System.Nullable<int> _Weightage;

        private System.Nullable<System.TimeSpan> _ExpectedTimeToAnswer;

        private EntitySet<Answer> _Answers;

        private EntitySet<TestDetail> _TestDetails;

        private EntityRef<Chapter> _Chapter;

        private EntityRef<QuestionType> _QuestionType;

        private EntityRef<Topic> _Topic;

    #region Extensibility Method Definitions
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnQuestionIdChanging(int value);
    partial void OnQuestionIdChanged();
    partial void OnQuestionTextChanging(string value);
    partial void OnQuestionTextChanged();
    partial void OnTopicIdChanging(System.Nullable<int> value);
    partial void OnTopicIdChanged();
    partial void OnMarksChanging(System.Nullable<int> value);
    partial void OnMarksChanged();
    partial void OnQuestionTypeIdChanging(System.Nullable<int> value);
    partial void OnQuestionTypeIdChanged();
    partial void OnChapterIdChanging(System.Nullable<int> value);
    partial void OnChapterIdChanged();
    partial void OnWeightageChanging(System.Nullable<int> value);
    partial void OnWeightageChanged();
    partial void OnExpectedTimeToAnswerChanging(System.Nullable<System.TimeSpan> value);
    partial void OnExpectedTimeToAnswerChanged();
    #endregion

        public Question()
        {
            this._Answers = new EntitySet<Answer>(new Action<Answer>(this.attach_Answers), new Action<Answer>(this.detach_Answers));
            this._TestDetails = new EntitySet<TestDetail>(new Action<TestDetail>(this.attach_TestDetails), new Action<TestDetail>(this.detach_TestDetails));
            this._Chapter = default(EntityRef<Chapter>);
            this._QuestionType = default(EntityRef<QuestionType>);
            this._Topic = default(EntityRef<Topic>);
            OnCreated();
        }

        [Column(Storage="_QuestionId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
        public int QuestionId
        {
            get
            {
                return this._QuestionId;
            }
            set
            {
                if ((this._QuestionId != value))
                {
                    this.OnQuestionIdChanging(value);
                    this.SendPropertyChanging();
                    this._QuestionId = value;
                    this.SendPropertyChanged("QuestionId");
                    this.OnQuestionIdChanged();
                }
            }
        }

        [Column(Storage="_QuestionText", DbType="NVarChar(MAX)")]
        public string QuestionText
        {
            get
            {
                return this._QuestionText;
            }
            set
            {
                if ((this._QuestionText != value))
                {
                    this.OnQuestionTextChanging(value);
                    this.SendPropertyChanging();
                    this._QuestionText = value;
                    this.SendPropertyChanged("QuestionText");
                    this.OnQuestionTextChanged();
                }
            }
        }

        [Column(Storage="_TopicId", DbType="Int")]
        public System.Nullable<int> TopicId
        {
            get
            {
                return this._TopicId;
            }
            set
            {
                if ((this._TopicId != value))
                {
                    if (this._Topic.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnTopicIdChanging(value);
                    this.SendPropertyChanging();
                    this._TopicId = value;
                    this.SendPropertyChanged("TopicId");
                    this.OnTopicIdChanged();
                }
            }
        }

        [Column(Storage="_Marks", DbType="Int")]
        public System.Nullable<int> Marks
        {
            get
            {
                return this._Marks;
            }
            set
            {
                if ((this._Marks != value))
                {
                    this.OnMarksChanging(value);
                    this.SendPropertyChanging();
                    this._Marks = value;
                    this.SendPropertyChanged("Marks");
                    this.OnMarksChanged();
                }
            }
        }

        [Column(Storage="_QuestionTypeId", DbType="Int")]
        public System.Nullable<int> QuestionTypeId
        {
            get
            {
                return this._QuestionTypeId;
            }
            set
            {
                if ((this._QuestionTypeId != value))
                {
                    if (this._QuestionType.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnQuestionTypeIdChanging(value);
                    this.SendPropertyChanging();
                    this._QuestionTypeId = value;
                    this.SendPropertyChanged("QuestionTypeId");
                    this.OnQuestionTypeIdChanged();
                }
            }
        }

        [Column(Storage="_ChapterId", DbType="Int")]
        public System.Nullable<int> ChapterId
        {
            get
            {
                return this._ChapterId;
            }
            set
            {
                if ((this._ChapterId != value))
                {
                    if (this._Chapter.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnChapterIdChanging(value);
                    this.SendPropertyChanging();
                    this._ChapterId = value;
                    this.SendPropertyChanged("ChapterId");
                    this.OnChapterIdChanged();
                }
            }
        }

        [Column(Storage="_Weightage", DbType="Int")]
        public System.Nullable<int> Weightage
        {
            get
            {
                return this._Weightage;
            }
            set
            {
                if ((this._Weightage != value))
                {
                    this.OnWeightageChanging(value);
                    this.SendPropertyChanging();
                    this._Weightage = value;
                    this.SendPropertyChanged("Weightage");
                    this.OnWeightageChanged();
                }
            }
        }

        [Column(Storage="_ExpectedTimeToAnswer", DbType="Time")]
        public System.Nullable<System.TimeSpan> ExpectedTimeToAnswer
        {
            get
            {
                return this._ExpectedTimeToAnswer;
            }
            set
            {
                if ((this._ExpectedTimeToAnswer != value))
                {
                    this.OnExpectedTimeToAnswerChanging(value);
                    this.SendPropertyChanging();
                    this._ExpectedTimeToAnswer = value;
                    this.SendPropertyChanged("ExpectedTimeToAnswer");
                    this.OnExpectedTimeToAnswerChanged();
                }
            }
        }

        [Association(Name="Question_Answer", Storage="_Answers", ThisKey="QuestionId", OtherKey="QuestionId")]
        public EntitySet<Answer> Answers
        {
            get
            {
                return this._Answers;
            }
            set
            {
                this._Answers.Assign(value);
            }
        }

        [Association(Name="Question_TestDetail", Storage="_TestDetails", ThisKey="QuestionId", OtherKey="QuestionId")]
        public EntitySet<TestDetail> TestDetails
        {
            get
            {
                return this._TestDetails;
            }
            set
            {
                this._TestDetails.Assign(value);
            }
        }

        [Association(Name="Chapter_Question", Storage="_Chapter", ThisKey="ChapterId", OtherKey="ChapterId", IsForeignKey=true)]
        public Chapter Chapter
        {
            get
            {
                return this._Chapter.Entity;
            }
            set
            {
                Chapter previousValue = this._Chapter.Entity;
                if (((previousValue != value) 
                            || (this._Chapter.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Chapter.Entity = null;
                        previousValue.Questions.Remove(this);
                    }
                    this._Chapter.Entity = value;
                    if ((value != null))
                    {
                        value.Questions.Add(this);
                        this._ChapterId = value.ChapterId;
                    }
                    else
                    {
                        this._ChapterId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Chapter");
                }
            }
        }

        [Association(Name="QuestionType_Question", Storage="_QuestionType", ThisKey="QuestionTypeId", OtherKey="QuestionTypeId", IsForeignKey=true)]
        public QuestionType QuestionType
        {
            get
            {
                return this._QuestionType.Entity;
            }
            set
            {
                QuestionType previousValue = this._QuestionType.Entity;
                if (((previousValue != value) 
                            || (this._QuestionType.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._QuestionType.Entity = null;
                        previousValue.Questions.Remove(this);
                    }
                    this._QuestionType.Entity = value;
                    if ((value != null))
                    {
                        value.Questions.Add(this);
                        this._QuestionTypeId = value.QuestionTypeId;
                    }
                    else
                    {
                        this._QuestionTypeId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("QuestionType");
                }
            }
        }

        [Association(Name="Topic_Question", Storage="_Topic", ThisKey="TopicId", OtherKey="TopicId", IsForeignKey=true)]
        public Topic Topic
        {
            get
            {
                return this._Topic.Entity;
            }
            set
            {
                Topic previousValue = this._Topic.Entity;
                if (((previousValue != value) 
                            || (this._Topic.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Topic.Entity = null;
                        previousValue.Questions.Remove(this);
                    }
                    this._Topic.Entity = value;
                    if ((value != null))
                    {
                        value.Questions.Add(this);
                        this._TopicId = value.TopicId;
                    }
                    else
                    {
                        this._TopicId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Topic");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_Answers(Answer entity)
        {
            this.SendPropertyChanging();
            entity.Question = this;
        }

        private void detach_Answers(Answer entity)
        {
            this.SendPropertyChanging();
            entity.Question = null;
        }

        private void attach_TestDetails(TestDetail entity)
        {
            this.SendPropertyChanging();
            entity.Question = this;
        }

        private void detach_TestDetails(TestDetail entity)
        {
            this.SendPropertyChanging();
            entity.Question = null;
        }
    }