public static bool CheckIfDatabaseExists()
        {
            CardContext databaseContext = new CardContext();
            bool        databaseExists  = databaseContext.Database.Exists();

            return(databaseExists);
        }
        public static int CreateLoadDatabase()
        {
            var cardList = ProvideCardList();
            int count    = 0;

            using (var cardContext = new CardContext())
            {
                try
                {
                    int dummyIdCount = 0;

                    foreach (var card in cardList)
                    {
                        if (card.mechanics != null)
                        {
                            foreach (var mechanic in card.mechanics)
                            {
                                mechanic.cardMechanicId = dummyIdCount + 1;

                                if (!cardContext.CardMechanics.Any(o => o.cardMechanicId == mechanic.cardMechanicId))
                                {
                                    cardContext.Entry(mechanic).State = System.Data.Entity.EntityState.Added;
                                }
                                if (cardContext.CardMechanics.Any(o => o.cardMechanicId == mechanic.cardMechanicId))
                                {
                                    cardContext.Entry(mechanic).State = System.Data.Entity.EntityState.Modified;
                                }

                                dummyIdCount += 1;
                            }
                        }

                        if (!cardContext.Cards.Any(o => o.cardId == card.cardId))
                        {
                            cardContext.Cards.Add(card);
                            cardContext.Entry(card).State = System.Data.Entity.EntityState.Added;
                        }
                        else if (cardContext.Cards.Any(o => o.cardId == card.cardId))
                        {
                            cardContext.Cards.Attach(card);
                            cardContext.Entry(card).State = System.Data.Entity.EntityState.Modified;
                        }
                    }

                    //foreach (var dbEntityEntry in db.ChangeTracker.Entries<Card>())
                    //{
                    //    System.Diagnostics.Debug.WriteLine(dbEntityEntry.State);
                    //    System.Diagnostics.Debug.WriteLine(dbEntityEntry.Entity.cardId + " " + dbEntityEntry.Entity.name);
                    //}

                    //foreach (var dbEntityEntry in db.ChangeTracker.Entries<CardMechanic>())
                    //{
                    //    System.Diagnostics.Debug.WriteLine(dbEntityEntry.State);
                    //    System.Diagnostics.Debug.WriteLine(dbEntityEntry.Entity.cardMechanicId + " " + dbEntityEntry.Entity.name);
                    //}

                    //db.Database.Log = Console.WriteLine;

                    cardContext.SaveChanges();

                    count = (from c in cardContext.Cards
                             select c).Count();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var validationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }

                return(count);
            }
        }