public BlogQuestionRepository() { #region 初始化问题集合 this._questions = new HashSet <BlogQuestion>(); this._newQ = new HashSet <BlogQuestion>(); this._modifiedQ = new HashSet <BlogQuestion>(); this._removedQ = new HashSet <BlogQuestion>(); #endregion #region 初始化答案集合 this._answerDic = new Dictionary <Guid, HashSet <BlogAnswer> >(); this._newanswerDic = new Dictionary <Guid, HashSet <BlogAnswer> >(); this._modifiedanswerDic = new Dictionary <Guid, HashSet <BlogAnswer> >(); this._removedanswerDic = new Dictionary <Guid, HashSet <BlogAnswer> >(); #endregion //初始化加载问题集合 this._questions = BlogQuestionPersist.GetAllQuestions(); }
public IList <BlogQuestion> FetchQuestions(int startIndex, int count, Guid categoryId) { return(BlogQuestionPersist.GetList(categoryId, startIndex, count)); }
public void PersistAll() { #region 转换成DataTable //新添加元素 DataTable newQuestionsTable = new DataTable("NewQuestions"); DataTable newAnswersTable = new DataTable("NewAnswers"); //修改过的元素 DataTable modifiedQuestionsTable = new DataTable("ModifiedQuestions"); //被删除的元素 DataTable removedQuestionsTable = new DataTable("RemovedQuestions"); //新博文 foreach (BlogQuestion q in this._newQ) { q.AlterToRow(newQuestionsTable); } //新回复 foreach (Guid id in this._newanswerDic.Keys) { foreach (BlogAnswer a in this._newanswerDic[id]) { a.AlterToRow(newAnswersTable); } } //更新的博文 foreach (BlogQuestion q in this._modifiedQ) { q.AlterToRow(modifiedQuestionsTable); } //删除的博文 foreach (BlogQuestion q in this._removedQ) { q.AlterToRow(removedQuestionsTable); } #endregion #region 持久化 //添加 BlogQuestionPersist.AddAll(newQuestionsTable); BlogQuestionPersist.AnswerToQuestion(newAnswersTable); //更新 BlogQuestionPersist.UpdateAll(modifiedQuestionsTable); //删除 //BlogQuestionPersist.RemoveAll(removedQuestionsTable); #endregion #region 释放内存 this._newQ.Clear(); this._newanswerDic.Clear(); this._removedQ.Clear(); this._modifiedQ.Clear(); #endregion }