Example #1
0
        public void PersistAll()
        {
            //新实例数据表
            DataTable newTable = new DataTable("NewTable");

            //修改的实例数据表
            DataTable modifiedTable = new DataTable("ModifiedTable");

            //删除的实例数据表
            DataTable removedTable = new DataTable("removedTable");

            foreach (TEntity entity in this._newList)
            {
                entity.AlterToRow(newTable);
            }

            foreach (TEntity entity in this._modifiedList)
            {
                entity.AlterToRow(modifiedTable);
            }

            foreach (TEntity entity in this._removedList)
            {
                entity.AlterToRow(removedTable);
            }


            if (newTable.Rows.Count != 0)
            {
                TPersist <TEntity> .PersistAll(newTable, DbOperation.Insert);
            }

            if (modifiedTable.Rows.Count != 0)
            {
                TPersist <TEntity> .PersistAll(modifiedTable, DbOperation.Update);
            }

            if (removedTable.Rows.Count != 0)
            {
                TPersist <TEntity> .PersistAll(removedTable, DbOperation.Delete);
            }


            this._newList.Clear();
            this._modifiedList.Clear();
            this._removedList.Clear();
        }
Example #2
0
        public void PersistAll()
        {
            #region 转换成DataTable
            //新添加元素
            DataTable newStorysTable   = new DataTable("NewStorys");
            DataTable newCommentsTable = new DataTable("NewComments");

            //修改过的元素
            DataTable modifiedStorysTable   = new DataTable("ModifiedStorys");
            DataTable modifiedCommentsTable = new DataTable("ModifiedComments");

            //被删除的元素
            DataTable removedStorysTable   = new DataTable("RemovedStorys");
            DataTable removedCommentsTable = new DataTable("RemovedComments");

            //新博文
            foreach (BlogStory bs in this._newStorys)
            {
                bs.AlterToRow(newStorysTable);
            }

            //新回复
            foreach (Guid id in this._newCommentDic.Keys)
            {
                foreach (BlogComment c in this._newCommentDic[id])
                {
                    c.AlterToRow(newCommentsTable);
                }
            }

            //更新的博文
            foreach (BlogStory bs in this._modifiedStorys)
            {
                bs.AlterToRow(modifiedStorysTable);
            }
            //更新的回复
            foreach (Guid id in this._modifiedCommentDic.Keys)
            {
                foreach (BlogComment c in this._modifiedCommentDic[id])
                {
                    c.AlterToRow(modifiedCommentsTable);
                }
            }

            //删除的博文
            foreach (BlogStory bs in this._removedStorys)
            {
                bs.AlterToRow(removedStorysTable);
            }

            //删除的回复
            foreach (Guid id in this._removedCommentDic.Keys)
            {
                foreach (BlogComment c in this._removedCommentDic[id])
                {
                    c.AlterToRow(removedCommentsTable);
                }
            }

            #endregion

            #region 持久化

            //添加
            //BlogStoryPersist.AddAll(newStorysTable);
            TPersist <BlogStory> .PersistAll(newStorysTable, DbOperation.Insert);

            TPersist <BlogComment> .PersistAll(newCommentsTable, DbOperation.Insert);

            //BlogStoryPersist.AddComments(newCommentsTable);

            //更新
            TPersist <BlogStory> .PersistAll(modifiedStorysTable, DbOperation.Update);

            //TPersist<BlogComment>.PersistAll(modifiedCommentsTable, DbOperation.Update);

            //删除
            //BlogStoryPersist.RemoveAll(removedStorysTable);
            TPersist <BlogStory> .PersistAll(removedStorysTable, DbOperation.Delete);

            TPersist <BlogComment> .PersistAll(removedCommentsTable, DbOperation.Delete);

            #endregion

            #region 释放内存

            this._newStorys.Clear();
            this._newCommentDic.Clear();

            this._removedStorys.Clear();
            this._removedCommentDic.Clear();
            this._modifiedStorys.Clear();
            this._modifiedCommentDic.Clear();
            #endregion
        }