Exemplo n.º 1
0
 /// <summary>
 /// Generates and adds property maps based on the primary keys for the given <see cref="DbContext"/>. This is done by resolving an
 /// instance of the <see cref="DbContext"/> using a temporary <see cref="IServiceProvider"/> based on the <see cref="IServiceCollection"/>.
 /// This method is generally called from <see cref="IServiceCollection"/>.AddAutoMapper().
 /// </summary>
 public static void UseEntityFrameworkCoreModel <TContext>(this IMapperConfigurationExpression config, IServiceCollection services)
     where TContext : DbContext
 {
     using (var serviceProvider = services.BuildServiceProvider())
     {
         config.UseEntityFrameworkCoreModel <TContext>(serviceProvider);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Generates and adds property maps based on the primary keys for the given <see cref="DbContext"/>. This is done by creating an
 /// instance of the <see cref="DbContext"/> using the parameterless constructor.
 /// </summary>
 public static void UseEntityFrameworkCoreModel <TContext>(this IMapperConfigurationExpression config)
     where TContext : DbContext, new()
 {
     using (var context = new TContext())
     {
         config.UseEntityFrameworkCoreModel <TContext>(context.Model);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Generates and adds property maps based on the primary keys for the given <see cref="DbContext"/>. This is done by resolving an
 /// instance of the <see cref="DbContext"/> using the <see cref="IServiceProvider"/>. This method is generally used when you are configuring
 /// AutoMapper using static initialization via <see cref="Mapper.Initialize(Action{IMapperConfigurationExpression})"/>.
 /// </summary>
 public static void UseEntityFrameworkCoreModel <TContext>(this IMapperConfigurationExpression config, IServiceProvider serviceProvider)
     where TContext : DbContext
 {
     using (var scope = serviceProvider.CreateScope())
     {
         var context = scope.ServiceProvider.GetRequiredService <TContext>();
         config.UseEntityFrameworkCoreModel <TContext>(context.Model);
     }
 }