迁移样例代码到使用驱动程序版本2

本文关键字:驱动程序 版本 样例 代码 迁移 | 更新日期: 2023-09-27 18:02:28

我正试图从这里转换项目https://github.com/attilah/AngularJSAuthentication使用mongo驱动程序版本2最新的一个,所以我可以适应我当前的项目。

我几乎完成了我的迁移,但我面对一些我不知道如何转换的文件,因为我新进入web api 2和mongodb。

我面临的问题是:

  1. ApplicationIdentityContext.cs
  2. ApplicationUserManager.cs
  3. ApplicationRoleManager.cs

例如与ApplicationIdentityContext.cs我已经尝试了以下代码,但是否出现错误,我被困在这一点:

namespace AngularJSAuthentication.API
{
    using Entities;
    using Microsoft.AspNet.Identity.EntityFramework;
    using MongoDB.Driver;
    public class ApplicationIdentityContext : IdentityDbContext
    {
        public ApplicationIdentityContext(IMongoContext mongoContext)
            : this(mongoContext.Users, mongoContext.Roles)
        {
        }
        public ApplicationIdentityContext(IMongoCollection<User> users, IMongoCollection<Role> roles)
           : base(users, roles)
        {
       } 
    }
}

,然后编辑器显示错误,当我构建程序:

Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'MongoDB.Driver.IMongoCollection<AngularJSAuthentication.API.Entities.User>' to 'System.Data.Common.DbConnection' AngularJSAuthentication.API D:'Projects'AngularJSAuthentication-master'AngularJSAuthentication.API'ApplicationIdentityContext.cs 14 Active

这是我的repos: https://github.com/skanel/Angular2-WebApi2-Mongodb2-Authentication

你知道吗?

迁移样例代码到使用驱动程序版本2

看起来像是一个从1.9到2.0的突破性变化。包

AspNet.Identity。MongoDB不兼容新的MongoDB驱动程序版本2+。

因此错误是:'cannot convert from 'MongoDB.Driver.IMongoCollection<AngularJSAuthentication.API.Entities.User>' to 'System.Data.Common.DbConnection'