public static void MakeParalelUpdate() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<NewsDbContext, Configuration>()); var context = new NewsDbContext(); var firstNews = context.News.FirstOrDefault(); Console.WriteLine("First news current content: " + firstNews.Content); Console.WriteLine("Enter the new text: "); using (var transaction = context.Database.BeginTransaction()) { try { var newText = Console.ReadLine(); firstNews.Content = newText; context.SaveChanges(); transaction.Commit(); Console.WriteLine("Update successful"); } catch (Exception ex) { transaction.Rollback(); Console.WriteLine("Conflict occured! \nThe transcation has been rolled back!"); Console.WriteLine(ex.Message); MakeParalelUpdate(); } } }
public static void AssemblyInit(TestContext context) { using (var newsDbContext = new NewsDbContext()) { newsDbContext.Database.CreateIfNotExists(); } }
private static void UpdateNewsContent(News firstNews, NewsDbContext context) { Console.WriteLine("Text from DB: " + firstNews.Content); Console.Write("Enter the corrected text: "); string newContent = Console.ReadLine(); firstNews.Content = newContent; }
public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<NewsDbContext, Configuration>()); var database = new NewsDbContext(); // Problem 2. Concurrent Updates (Console App) ParalelUpdates.MakeParalelUpdate(); }
protected void Page_Load(object sender, EventArgs e) { if(this.ReaderId == string.Empty) { this.content.Visible = false; this.LikesLiteral.Text = db.Articles.Find(int.Parse(this.ArticleId)).Likes.Sum(l => l.Value).ToString(); } this.db = new NewsDbContext(); }
public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<NewsDbContext, Configuration>()); Console.WriteLine("Application started"); var contextFirstUser = new NewsDbContext(); var firstNews = contextFirstUser.News.FirstOrDefault(); bool running = true; do { if (firstNews != null) { UpdateNewsContent(firstNews, contextFirstUser); var contextSecondUser = new NewsDbContext(); firstNews = contextSecondUser.News.FirstOrDefault(); UpdateNewsContent(firstNews, contextSecondUser); contextFirstUser.SaveChanges(); try { contextSecondUser.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { Console.WriteLine("Conflict! Text from DB: {0}. Enter the corrected text:", firstNews.Content); Console.WriteLine(ex.Message); UpdateNewsContent(firstNews, contextSecondUser); } } else { Console.WriteLine("Sorry, no news yet!"); } } while (!running); }
protected void Page_Load(object sender, EventArgs e) { this.db = new NewsDbContext(); }
public IEnumerable<Category> Categories_GetData() { var localDb = new NewsDbContext(); return localDb.Categories.OrderBy(b => b.Name).ToList(); }
public ArticleDetails() { this.dbContext = new NewsDbContext(); }
public News() { this.db = new NewsDbContext(); }
public BasePage() { this.dbContext = new NewsDbContext(); }
public Articles() { this.db = new NewsDbContext(); }
public Home() { this.dbContext = new NewsDbContext(); }
public EditArticles() { this.dbContext = new NewsDbContext(); }
public EditCategories() { this.dbContext = new NewsDbContext(); }
public NewsRepository(NewsDbContext context) { _context = context; }
public Categories() { this.db = new NewsDbContext(); }