Пример #1
0
        public async Task AddCommentsToDBAsync(List <Comment> comments)
        {
            using (ModelDB db = new ModelDB())
            {
                IEnumerable <Comment> bdComments = GetCommentsFromBD();

                IEnumerable <Comment> finds = bdComments.Except(comments, new MyEqualityComparer());
                if (finds.Count() > 0 && finds != null)
                {
                    int count = 0;

                    foreach (Comment find in finds)
                    {
                        db.Comments.Add(find);
                        count++;
                    }
                    await db.SaveChangesAsync();

                    Console.WriteLine($"Добавленно {count} новых записей");
                }
                else
                {
                    Console.WriteLine("Новые записи отсутствуют");
                }
            }
        }
Пример #2
0
        public List <Comment> GetCommentsFromBD()
        {
            List <Comment> comments;

            using (ModelDB db = new ModelDB())
            {
                comments = db.Comments.ToList();
            }
            return(comments);
        }