0

I'm trying to configure automapper.Collections for my aspnet boilerplate core project, how do I get the DBContext to configure:

cfg.SetGeneratePropertyMaps> ();

ie in:

   public override void Initialize()
    {
        var thisAssembly = typeof(ApplicationModule).GetAssembly();

        IocManager.RegisterAssemblyByConvention(thisAssembly);

        Configuration.Modules.AbpAutoMapper().Configurators.Add(
            // Scan the assembly for classes which inherit from AutoMapper.Profile
            cfg => {
                cfg.AddProfiles(thisAssembly);
                cfg.AddCollectionMappers();
                cfg.SetGeneratePropertyMaps<GenerateEntityFrameworkCorePrimaryKeyPropertyMaps<dbcontext>> ();
            }
        );
    }
DLedge
  • 83
  • 13
  • Erm, type it out? – aaron Mar 03 '19 at 05:18
  • Ok, thought I needed to get it from Abp, added using Microsoft.EntityFrameworkCore; and got past that issue. but now I'm getting the following exception: InvalidOperationException: Use AddEntityFrameworkCoreKeys instead of using SetGeneratePropertyMaps. for this cfg.SetGeneratePropertyMaps> (); but I don't seem to have an implementation of AddEntityFrameworkCoreKeys – DLedge Mar 03 '19 at 06:50
  • 1. Use the DbContext implemented in your *.EntityFrameworkCore project. 2. It should be `UseEntityFrameworkCoreModel`. – aaron Mar 03 '19 at 07:10
  • Sorry for all the questions, I've defined as follows but I'm not getting the syntax right, what am I missing? cfg.UseEntityFrameworkCoreModel>(); – DLedge Mar 03 '19 at 07:38
  • `cfg.UseEntityFrameworkCoreModel();` – aaron Mar 03 '19 at 07:55
  • I still seem to be missing something, I get the following compile error when using the above: Error CS0310 'MyDbContext' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TContext' in the generic type or method 'MapperConfigurationExpressionExtensions.UseEntityFrameworkCoreModel(IMapperConfigurationExpression)' – DLedge Mar 03 '19 at 08:22

1 Answers1

0

My solution was using the Abp DefaultDbContextResolver

// We are just creating the DbContext for the model
// So we don't need a connection string
var dbContext = IocManager
    .Resolve<DefaultDbContextResolver>()
    .Resolve<MyDbContext>(null, null);
cfg.UseEntityFrameworkCoreModel(dbContext.Model);