Exemplo n.º 1
0
        private static void HandleConcurrentUpdates()
        {
            using (var context = new NewsContext())
            {
                var firstNews = context.News.FirstOrDefault();
                Console.WriteLine("Text from DB: {0}", firstNews.Content);

                Console.WriteLine("Enter the corrected text: ");
                var newContent = Console.ReadLine();

                firstNews.Content = newContent;

                try
                {
                    context.SaveChanges();
                    Console.WriteLine("Changes successfully saved in the DB.");
                }
                catch (DbUpdateConcurrencyException)
                {
                    Console.WriteLine("Conflict!");

                    HandleConcurrentUpdates();
                }
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            var context = new NewsContext();
            var newsCount = context.News.Count();

            //// Problem 2.
            // Start two consoles simultaneously and fill the input one by one.

            HandleConcurrentUpdates();
        }