/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { using (var db = new GameContext()) { db.Database.EnsureCreated(); } this.InitializeComponent(); this.Suspending += this.OnSuspending; }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { using (var db = new GameContext()) { // TODO: Apply migrations an app start } this.InitializeComponent(); this.Suspending += this.OnSuspending; }
public static IEnumerable<Game> GetTopGames() { using (var db = new GameContext()) { var topGames = db.Games .OrderByDescending(g => g.ClicksPerSecond) .Take(3); return topGames; } }
public static void RecordGame(int duration, int clicks) { var game = new Game { Duration = duration, Clicks = clicks, ClicksPerSecond = (double)clicks / duration, Played = DateTime.Now }; using (var db = new GameContext()) { db.Games.Add(game); db.SaveChanges(); } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { try { using (var db = new GameContext()) { db.Database.AsRelational().ApplyMigrations(); } } catch (Exception e) { throw e; } this.InitializeComponent(); this.Suspending += this.OnSuspending; }