11using IdentityServer4 . EntityFramework . DbContexts ;
22using IdentityServer4 . EntityFramework . Mappers ;
33using Microsoft . eShopOnContainers . Services . Identity . API . Configuration ;
4+ using Microsoft . EntityFrameworkCore ;
45using Microsoft . Extensions . Configuration ;
56using System . Collections . Generic ;
67using System . Linq ;
@@ -24,33 +25,22 @@ public async Task SeedAsync(ConfigurationDbContext context, IConfiguration confi
2425 { "OrderingApi" , configuration . GetValue < string > ( "OrderingApiClient" ) }
2526 } ;
2627
27- if ( ! context . Clients . Any ( ) )
28+ if ( ! await context . Clients . AnyAsync ( ) )
2829 {
29- foreach ( var client in Config . GetClients ( clientUrls ) )
30- {
31- await context . Clients . AddAsync ( client . ToEntity ( ) ) ;
32- }
33- await context . SaveChangesAsync ( ) ;
30+ context . Clients . AddRange ( Config . GetClients ( clientUrls ) . Select ( client => client . ToEntity ( ) ) ) ;
3431 }
3532
36- if ( ! context . IdentityResources . Any ( ) )
33+ if ( ! await context . IdentityResources . AnyAsync ( ) )
3734 {
38- foreach ( var resource in Config . GetResources ( ) )
39- {
40- await context . IdentityResources . AddAsync ( resource . ToEntity ( ) ) ;
41- }
42- await context . SaveChangesAsync ( ) ;
35+ context . IdentityResources . AddRange ( Config . GetResources ( ) . Select ( resource => resource . ToEntity ( ) ) ) ;
4336 }
4437
45- if ( ! context . ApiResources . Any ( ) )
38+ if ( ! await context . ApiResources . AnyAsync ( ) )
4639 {
47- foreach ( var api in Config . GetApis ( ) )
48- {
49- await context . ApiResources . AddAsync ( api . ToEntity ( ) ) ;
50- }
51-
52- await context . SaveChangesAsync ( ) ;
40+ context . ApiResources . AddRange ( Config . GetApis ( ) . Select ( api => api . ToEntity ( ) ) ) ;
5341 }
42+
43+ await context . SaveChangesAsync ( ) ;
5444 }
5545 }
5646}
0 commit comments