0

I am using ASP.Net boilerplate framework + SQL Server 2016 in my project. Recently I have faced a challenge with migration from SQL Server to MongoDB. I have found that it is possible with ASP .NET boilerplate and installed required NuGet packages, however, due to the lack of documentation the only thing I have managed to do is to define respective RepositoryBase class:

public abstract class MyRepositoryBase<TEntity, TPrimaryKey> : MongoDbRepositoryBase<TEntity, TPrimaryKey>
    where TEntity : class, IEntity<TPrimaryKey>
{
    protected MyRepositoryBase(IMongoDatabaseProvider databaseProvider)
        : base(databaseProvider)
    {

    }

}

As far as I understand, first of all, I need to define connection string somewhere now. And then populate the database with required basic data(which previously had been done by EF Core migrations). Obviously, EF Core in the new approach is obsolete so does that mean for my DbContext class that it is obsolete as well? Actually, there are plenty of questions in relation to ASP .NET boilerplate and MongoDB integration, therefore my current post is actually a request for provision of some kind of example of the existing integration. Thank you in advance.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197

1 Answers1

0

You can register your module by depending on it on your web module.

[DependsOn(typeof(YourMongoDbModule))]
public class YourWebModule : AbpModule
{

}

I think you have to register the repository with:

IocManager.Register(typeof(IMongoRepository<>), typeof(MongoRepository<>), Abp.Dependency.DependencyLifeStyle.Singleton);

You can refer this sample.

Look at this comment also.

Here is a framework which maps EF Core to Mongo DB.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • Hm... Looks like these are answers to all my questions. I'll review tomorrow and will provide you a feedback. Thank you for your help! – Gaius Caesar Mar 12 '18 at 20:35
  • sample you have provided has targeting framework .net standard however all of required entities at my solution placed inside project with targeting framework .net core therefore I cannot reference it. So I managed to create my own base repository which inherits MongoDbRepositoryBase however it is still unclear what Context I should use for it and where to configure it(e.g. define connection string)? So on start of the project I am getting System.TypeLoadException: 'Method 'GetAsync' in type 'Abp.BackgroundJobs.BackgroundJobStore' does not have an implementation.' – Gaius Caesar Mar 19 '18 at 17:47
  • so this is probably a good question to aspnetboilerplate team to provide a kind of a step-by-step guide for this purpose. @vivekn – Gaius Caesar Mar 19 '18 at 17:53