static void Main() { var context = new NewsDBContext(); var data = context.News.Find(1); //WARNING: Concurency handling should be tested by running two instances of the app. while (true) { try { data.Content = Console.ReadLine(); context.SaveChanges(); Console.WriteLine("Changes successfully saved in the DB."); break; } catch (DbUpdateConcurrencyException exc) { exc.Entries.Single().Reload(); Console.WriteLine("Conflict! Text from DB:" + context.News.Find(1).Content + ". Enter the corrected text:"); } } }
static void Main() { var context = new NewsDBContext(); var newContext = new NewsDBContext(); var firstNews = context.News.FirstOrDefault(); Console.WriteLine("Application started"); Console.Write("Text from DB: "); Console.WriteLine(firstNews.NewsContent); Console.WriteLine("Enter the corrected text: "); firstNews.NewsContent = Console.ReadLine(); try { context.SaveChanges(); Console.WriteLine("Changes successfully saved in the DB."); } catch (DbUpdateConcurrencyException ex) { var textFromDB = newContext.News.FirstOrDefault(); Console.WriteLine("Conflict! Text from DB: {0}. Enter the corrected text:", textFromDB.NewsContent); Main(); } }
public static void Main() { using (var db = new NewsDBContext()) { db.News.Add(new News { Content = "Some very long and interesting content!" }); db.SaveChanges(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); news = new News(); editNews = new EditNews(); success = new Success(); error = new Error(); Application.Run(news); using (var context = new NewsDBContext()) { var loadedEntity = context.News.First(); CatchConcurrencyConflict(context, loadedEntity); } }
public NewsletterRepository(NewsDBContext context) { _context = context; }
public CommentRepository(NewsDBContext context) { _context = context; }
public UnitOfWork(NewsDBContext context, IMapper mapper, IConfiguration configuration) { _Context = context; _mapper = mapper; _configuration = configuration; }
public RankController(NewsDBContext context) { _context = context; }
public CategoryRepository(NewsDBContext context, IMapper mapper) { _context = context; _mapper = mapper; _context.CheckArgumentIsNull(nameof(_context)); }
public NewsService(NewsDBContext dbContext) { this._dbContext = dbContext; }