static void Main() { //To run simultaneously two instances of your app you have to configure your solution by this way: //Right-Click -> Properties -> Multiple Startup Projects -> and select both projects actions to Start var contextSecond = new NewsContext(); var contextFirst = new NewsContext(); Console.WriteLine("Second User"); Console.WriteLine("Application started."); var firstNewsSecondUser = contextSecond.News.First(); Console.WriteLine("Text from DB:" + firstNewsSecondUser.Content); Console.WriteLine("Enter the corrected text:"); string newValue2 = Console.ReadLine(); firstNewsSecondUser.Content = newValue2; Console.WriteLine("User input: " + newValue2); try { contextSecond.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { var firstContent = contextFirst.News.First(); Console.WriteLine("Conflict! Text from DB: " + firstContent.Content); Console.WriteLine("Enter the corrected text:"); string newValue = Console.ReadLine(); firstContent.Content = newValue; Console.WriteLine("User input: " + newValue); contextFirst.SaveChanges(); } Console.WriteLine("Changes successfully saved in the DB."); }
static void Main() { //To run simultaneously two instances of your app you have to configure your solution by this way: //Right-Click -> Properties -> Multiple Startup Projects -> and select both projects actions to Start var contextFirst = new NewsContext(); Console.WriteLine("First User"); Console.WriteLine("Application started."); var firstNewsFirstUser = contextFirst.News.First(); //Step 1 Console.WriteLine("Text from DB:" + firstNewsFirstUser.Content); Console.WriteLine("Enter the corrected text:"); //Step 2 string newValue = Console.ReadLine(); firstNewsFirstUser.Content = newValue; Console.WriteLine("User input: " + newValue); //Step 3 contextFirst.SaveChanges(); Console.WriteLine("Changes succesfully saved in the DB."); }