简体   繁体   中英

The provider for the source IQueryable doesn't implement IDbAsyncQueryProvider

I'm intending to create pagination on my api using the following example: https://www.codeproject.com/Articles/1073488/Paging-in-ASP-NET-Web-API I've implemented all code and its running until I hit the following line of code:

var results = await projection.ToListAsync();

then it causes a runtime error:

"The provider for the source IQueryable doesn't implement IDbAsyncQueryProvider..."

I've researched this error and tried to initialize the Mapper in my Global.asax.cs file like so:

        protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        Mapper.Initialize(cfg => cfg.CreateMap<Logging.Models.LogsModel, Log>());
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

    }

This doesn't resolve the problem, does anybody know what I'm doing wrong initializing Automapper?

Thanks in Advance.

Here is the implementing code in my controller:

        public async Task<IHttpActionResult> Get(int? page = null, int pageSize = 10, string orderBy = nameof(LogsModel.Id), bool ascending = true)
    {
        if (page == null)
        {
            return Ok(_repository.GetLogs());
        }
        else
        {
            var returnList =  _repository.GetLogs().AsQueryable();
            returnList = returnList as IQueryable<LogsModel>;
            var logsout = await CreatePagedResults<LogsModel, Log>(returnList, page.Value, pageSize, orderBy, ascending);
            return Ok(logsout);
        }
    }

and heres the definition of GetLogs:

        public IEnumerable<LogsModel> GetLogs()
    {
        List<LogsModel> logs = Logs.ToList<LogsModel>();
        return logs;
    }

我有一个类似的问题,问题是我使用 System.Data.Entity 而不是 Microsoft.EntityFrameworkCore

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM