/// <summary> /// Fast bulk insert to copy players of a grid to the log /// </summary> /// <param name="gridId"></param> public void BulkInsertPlayerLogs(int gridId) { var playerLogList = new List<PlayerLog>(); var players = db.Players.Where(p => p.GridId == gridId).ToList(); foreach (var p in players) { var playerLog = new PlayerLog(p); playerLogList.Add(playerLog); } var playerLogTable = playerLogList.ToDataTable(); var connStr = ctx.Database.Connection.ConnectionString; using (var bcp = new SqlBulkCopy(connStr)) { bcp.DestinationTableName = "PlayerLogs"; bcp.WriteToServer(playerLogTable); } }
/// <summary> /// Add a player log entry to the database /// </summary> public void Add(PlayerLog playerLog, bool saveChanges) { db.PlayerLogs.Add(playerLog); if (saveChanges) db.SaveChanges(); }
/// <summary> /// Remove a player log entry from database /// </summary> public void Remove(PlayerLog playerLog) { db.PlayerLogs.Remove(playerLog); db.SaveChanges(); }
/// <summary> /// Add a player log entry to the database /// </summary> public void Add(PlayerLog playerLog) { Add(playerLog, true); }