예제 #1
0
파일: Data.cs 프로젝트: Jaqb-98/P4-lab4
        public async Task AddCoachesAsync(ICollection <Coach> coaches)
        {
            await using var context = new CollegeFootballContext();
            context.Database.OpenConnection();
            await context.Coaches.AddRangeAsync(coaches);

            await context.SaveChangesAsync();

            await context.Database.CloseConnectionAsync();
        }
예제 #2
0
파일: Data.cs 프로젝트: Jaqb-98/P4-lab4
        public async Task UpdateAsync()
        {
            await using var context = new CollegeFootballContext();
            context.Database.OpenConnection();
            foreach (var team in context.Teams)
            {
                var a = GetTeamCoachAsync(team.School).Result;
                if (a != null)
                {
                    team.Coach   = a;
                    team.CoachId = a.Id;
                }
            }
            await context.SaveChangesAsync();

            context.Database.CloseConnection();
        }
예제 #3
0
파일: Data.cs 프로젝트: Jaqb-98/P4-lab4
        public async Task AddTeamsAsync(ICollection <Team> teams)
        {
            await using var context = new CollegeFootballContext();
            context.Database.OpenConnection();
            await context.Teams.AddRangeAsync(teams);

            context.Database.OpenConnection();
            try
            {
                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.Teams ON");
                await context.SaveChangesAsync();

                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.Teams OFF");
            }
            finally
            {
                await context.Database.CloseConnectionAsync();
            }
        }