Пример #1
0
        public void Migrate()
        {
            var oldUnreadPosts = SourceDbContext.UnreadPosts.ToList();

            foreach (var oldUnreadPost in oldUnreadPosts)
            {
                var newEntity = new UnreadPost()
                {
                    Id     = _unreadPostKeyMapper.MapKey(oldUnreadPost.Id),
                    PostId = _postKeyMapper.MapKey(oldUnreadPost.PostId),
                    UserId = _userKeyMapper.MapKey(oldUnreadPost.AccountId)
                };

                TargetDbContext.UnreadPosts.Add(newEntity);
            }

            TargetDbContext.SaveChanges();
        }
        public void Migrate()
        {
            var posts = SourceDbContext.Posts.ToList();

            foreach (var oldPost in posts)
            {
                var newEntity = new Post()
                {
                    Id       = _postKeyMapper.MapKey(oldPost.Id),
                    PostDate = oldPost.PostDate,
                    Content  = oldPost.Message,
                    PosterId = _userKeyMapper.MapKey(oldPost.PosterId),
                    TopicId  = _topicKeyMapper.MapKey(oldPost.TopicId)
                };

                TargetDbContext.Posts.Add(newEntity);
            }

            TargetDbContext.SaveChanges();
        }