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); }
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); }
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); } }
public AccountsController(intrusiveContext context, intrusiveContextReadOnly contextRead) { _context = context; _contextRead = contextRead; }
public AbilitiesController(intrusiveContext context) { _context = context; }
public PlayersController(intrusiveContext context) { _context = context; }
//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"); }
public MapsController(intrusiveContext context) { _context = context; }
public HighscoreController(intrusiveContext context, intrusiveContextReadOnly contextRead) { _context = context; _contextRead = contextRead; }
public TestController(intrusiveContext context, intrusiveContextReadOnly contextRead) { _context = context; _contextRead = contextRead; }