diff --git a/src/AutoMapper.Collection.EntityFrameworkCore/GenerateEntityFrameworkCorePrimaryKeyPropertyMaps.cs b/src/AutoMapper.Collection.EntityFrameworkCore/GenerateEntityFrameworkCorePrimaryKeyPropertyMaps.cs index d4e5e4b..f8e6ced 100644 --- a/src/AutoMapper.Collection.EntityFrameworkCore/GenerateEntityFrameworkCorePrimaryKeyPropertyMaps.cs +++ b/src/AutoMapper.Collection.EntityFrameworkCore/GenerateEntityFrameworkCorePrimaryKeyPropertyMaps.cs @@ -7,8 +7,7 @@ namespace AutoMapper.EntityFrameworkCore { - public class GenerateEntityFrameworkCorePrimaryKeyPropertyMaps : IGeneratePropertyMaps - where TDatabaseContext : DbContext + public class GenerateEntityFrameworkCorePrimaryKeyPropertyMaps : IGeneratePropertyMaps { private readonly IModel _model; @@ -20,7 +19,7 @@ public IEnumerable GeneratePropertyMaps(TypeMap typeMap) { var propertyMaps = typeMap.PropertyMaps; var keyMembers = _model.FindEntityType(typeMap.DestinationType)?.FindPrimaryKey().Properties ?? new List(); - return keyMembers.Select(m => propertyMaps.FirstOrDefault(p => p.DestinationMember.Name == m.Name)); + return propertyMaps.Where(p => keyMembers.Any(m => m.Name == p.DestinationMember.Name)); } } } \ No newline at end of file diff --git a/src/AutoMapper.Collection.EntityFrameworkCore/MapperConfigurationExpressionExtensions.cs b/src/AutoMapper.Collection.EntityFrameworkCore/MapperConfigurationExpressionExtensions.cs index 81862da..def6bd6 100644 --- a/src/AutoMapper.Collection.EntityFrameworkCore/MapperConfigurationExpressionExtensions.cs +++ b/src/AutoMapper.Collection.EntityFrameworkCore/MapperConfigurationExpressionExtensions.cs @@ -18,7 +18,7 @@ public static void UseEntityFrameworkCoreModel(this IMapperConfigurati { using (var context = new TContext()) { - config.UseEntityFrameworkCoreModel(context.Model); + config.UseEntityFrameworkCoreModel(context.Model); } } @@ -47,7 +47,7 @@ public static void UseEntityFrameworkCoreModel(this IMapperConfigurati using (var scope = serviceProvider.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService(); - config.UseEntityFrameworkCoreModel(context.Model); + config.UseEntityFrameworkCoreModel(context.Model); } } @@ -55,7 +55,7 @@ public static void UseEntityFrameworkCoreModel(this IMapperConfigurati /// Generates and adds property maps based on the primary keys for the given . This method is generally /// only used if you are using . /// - public static void UseEntityFrameworkCoreModel(this IMapperConfigurationExpression config, IModel model) - where TContext : DbContext => config.SetGeneratePropertyMaps(new GenerateEntityFrameworkCorePrimaryKeyPropertyMaps(model)); + public static void UseEntityFrameworkCoreModel(this IMapperConfigurationExpression config, IModel model) + => config.SetGeneratePropertyMaps(new GenerateEntityFrameworkCorePrimaryKeyPropertyMaps(model)); } }