Inheritance: DbContext
        /// <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;
        }
示例#2
0
        /// <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;
        }
示例#3
0
        public static IEnumerable<Game> GetTopGames()
        {
            using (var db = new GameContext())
            {
                var topGames = db.Games
                    .OrderByDescending(g => g.ClicksPerSecond)
                    .Take(3);

                return topGames;
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
        /// <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;
        }