Esempio n. 1
0
 public static void Reset()
 {
     using(SportContext context = new SportContext())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM Player");
         context.Database.ExecuteSqlCommand("DELETE FROM Team");
         context.Database.ExecuteSqlCommand("DELETE FROM Sport");
     }
 }
 public long GetTeamsForSport(int sportId)
 {
     Stopwatch watch = new Stopwatch();
     watch.Start();
     using (SportContext context = new SportContext())
     {
         var players = context.Teams.AsNoTracking().Include(x=>x.Players).Where(x => x.SportId == sportId).ToList();
     }
     watch.Stop();
     return watch.ElapsedMilliseconds;
 }
 public long GetPlayersForTeam(int teamId)
 {
     Stopwatch watch = new Stopwatch();
     watch.Start();
     using (SportContext context = new SportContext())
     {
         var players = context.Players.AsNoTracking().Where(x => x.TeamId == teamId).ToList();
     }
     watch.Stop();
     return watch.ElapsedMilliseconds;
 }
 public long GetPlayerByID(int id)
 {
     Stopwatch watch = new Stopwatch();
     watch.Start();
     using (SportContext context = new SportContext())
     {
         var player = context.Players.Find(id);
     }
     watch.Stop();
     return watch.ElapsedMilliseconds;
 }
 public long GetPlayerByID(int id)
 {
     Stopwatch watch = new Stopwatch();
     watch.Start();
     using (SportContext context = new SportContext())
     {
         var player = context.Players.AsNoTracking().Single(x => x.Id == id);
     }
     watch.Stop();
     return watch.ElapsedMilliseconds;
 }
 public long GetTeamsForSport(int sportId)
 {
     Stopwatch watch = new Stopwatch();
     watch.Start();
     using (SportContext context = new SportContext())
     {
         //var tmpFromSportPlayers = context.Sports
         //var tmpPlayers = context.Teams.Where(t => t.SportId == sportId).SelectMany(t => t.Players).ToList();
         var players = context.Teams.Include(x=>x.Players).Where(x => x.SportId == sportId).ToList();
     }
     watch.Stop();
     return watch.ElapsedMilliseconds;
 }
Esempio n. 7
0
        private static void AddSports(List<SportDTO> sports)
        {
            using (SportContext context = new SportContext())
            {
                foreach (var sport in sports)
                {
                    context.Sports.Add(new Sport()
                    {
                        Id = sport.Id,
                        Name = sport.Name
                    });
                }

                context.SaveChanges();
            }
        }
Esempio n. 8
0
        private static void AddTeams(List<TeamDTO> teams)
        {
            using (SportContext context = new SportContext())
            {
                foreach (var team in teams)
                {
                    context.Teams.Add(new Team()
                    {
                        Name = team.Name,
                        Id = team.Id,
                        SportId = team.SportId,
                        FoundingDate = team.FoundingDate
                    });
                }

                context.SaveChanges();
            }
        }
Esempio n. 9
0
        private static void AddPlayers(List<PlayerDTO> players)
        {
            using (SportContext context = new SportContext())
            {
                foreach (var player in players)
                {
                    context.Players.Add(new Player()
                    {
                        FirstName = player.FirstName,
                        LastName = player.LastName,
                        DateOfBirth = player.DateOfBirth,
                        TeamId = player.TeamId,
                        Id = player.Id
                    });
                }

                context.SaveChanges();
            }
        }
 public void CreateDatabase()
 {
     try { SportContext context = new SportContext(); }
     catch (Exception ex) { }
 }
 public EntityFrameworkReusingWithQueryContext()
 {
     _context = new SportContext();
 }
 public EntityFrameworkReusingContext()
 {
     _context = new SportContext();
 }