예제 #1
0
 public T Update <T>(T data) where T : class
 {
     try
     {
         using (var context = new intrusiveContext())
         {
             context.Add(data);
             context.SaveChanges();
         }
     }
     catch (DbUpdateException e)
     {
         Console.WriteLine(e.InnerException.Message);
     }
     return(data);
 }
예제 #2
0
        private intrusiveContext AddToContext <T>(intrusiveContext context, T entity, int count, int commitCount, bool recreateContext) where T : class
        {
            context.Set <T>().Add(entity);

            if (count % commitCount == 0)
            {
                context.SaveChanges();
                if (recreateContext)
                {
                    context.Dispose();
                    context = new intrusiveContext();
                    context.ChangeTracker.AutoDetectChangesEnabled = false;
                }
            }

            return(context);
        }
예제 #3
0
        public void EFCORETest()
        {
            try
            {
                using (var context = new intrusiveContext())
                {
                    var temp = context.Accounts.AsNoTracking().FirstOrDefault(acc => acc.AccountId == "TestAcc");
                    var test = context.Accounts.Where(acc => acc.AccountId == "TestAcc");
                    //Console.WriteLine(test.ToQueryString());
                    //var temp = context.Accounts.FirstOrDefault(acc => acc.AccountId == "TestAcc");
                    temp.LastName = "Track test";


                    context.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.InnerException.Message);
            }
        }
예제 #4
0
 public AccountsController(intrusiveContext context, intrusiveContextReadOnly contextRead)
 {
     _context     = context;
     _contextRead = contextRead;
 }
 public AbilitiesController(intrusiveContext context)
 {
     _context = context;
 }
예제 #6
0
 public PlayersController(intrusiveContext context)
 {
     _context = context;
 }
예제 #7
0
        //public List<TestModel> GetAllTest(string playerID)
        //{
        //    List<TestModel> matches = new List<TestModel>();

        //    using (MySqlConnection connection = CreateConnection())
        //    {
        //        matches = connection.Query<TestModel>("SELECT * FROM matches NATURAL JOIN (SELECT * FROM played_match WHERE player_id = @PlayerID) AS matches_played_by_player", new { PlayerID = playerID }).ToList();
        //    }

        //    return matches;
        //}



        public void InsertRandomData(int amount)
        {
            var personGenerator = new PersonNameGenerator();
            var placeGenerator  = new PlaceNameGenerator();

            intrusiveContext context = null;

            Random rnd = new Random(DateTime.UtcNow.Millisecond);

            int index = 105000;

            try
            {
                context = new intrusiveContext();

                context.ChangeTracker.AutoDetectChangesEnabled = false;

                for (int i = 0; i < amount; i++)
                {
                    Accounts tempAccount = new Accounts()
                    {
                        AccountId    = placeGenerator.GenerateRandomPlaceName() + index.ToString() + personGenerator.GenerateRandomFirstName(),
                        Email        = index.ToString(),
                        PasswordHash = index.ToString()
                    };

                    Players tempPlayer = new Players()
                    {
                        Experience = (uint)rnd.Next(10000001),
                        PlayerId   = tempAccount.AccountId
                    };


                    context.Add(tempAccount);
                    context.Add(tempPlayer);

                    if (i % 100 == 0)
                    {
                        context.SaveChanges();

                        context.Dispose();
                        context = new intrusiveContext();
                        context.ChangeTracker.AutoDetectChangesEnabled = false;
                    }


                    context.SaveChanges();

                    //connection.Query<AccountModel>("select * from accounts");
                    //Console.WriteLine("{0} inserted succesfully!", tempPlayer.PlayerId);
                    index++;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }



            //using (MySqlConnection connection = CreateConnection())
            //{
            //    int index = 0;
            //    try
            //    {
            //        connection.Open();

            //        for (int i = 0; i < amount; i++)
            //        {
            //            Accounts tempAccount = new Accounts()
            //            {
            //                AccountId = placeGenerator.GenerateRandomPlaceName() + index.ToString() + personGenerator.GenerateRandomFirstName(),
            //                Email = index.ToString(),
            //                PasswordHash = index.ToString()
            //            };

            //            Players tempPlayer = new Players()
            //            {
            //                Experience = (uint)rnd.Next(10000001),
            //                PlayerId = tempAccount.AccountId
            //            };
            //            connection.Insert(tempAccount);
            //            connection.Insert(tempPlayer);

            //            //connection.Query<AccountModel>("select * from accounts");
            //            Console.WriteLine("{0} inserted succesfully!", tempPlayer.PlayerId);
            //            index++;
            //        }

            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e.Message);
            //    }
            //}
            Console.WriteLine("All inserted");
        }
예제 #8
0
 public MapsController(intrusiveContext context)
 {
     _context = context;
 }
예제 #9
0
 public HighscoreController(intrusiveContext context, intrusiveContextReadOnly contextRead)
 {
     _context     = context;
     _contextRead = contextRead;
 }
예제 #10
0
 public TestController(intrusiveContext context, intrusiveContextReadOnly contextRead)
 {
     _context     = context;
     _contextRead = contextRead;
 }