C# 参数类型不能分配给参数类型,尽管它继承了

C# 参数类型不能分配给参数类型,尽管它继承了,c#,asp.net,asp.net-mvc-5,dbcontext,asp.net-identity-2,C#,Asp.net,Asp.net Mvc 5,Dbcontext,Asp.net Identity 2,我试图从头开始用ASP.net身份编写一个MVC应用程序。 为此,我学习了Ben Foster(和)的两个教程 但我还是停留在第二个教程上——配置UserManager。下面这句话对我不适用: // configure the user manager UserManagerFactory = () => { var usermanager = new UserManager<AppUser>( new UserS

我试图从头开始用ASP.net身份编写一个MVC应用程序。 为此,我学习了Ben Foster(和)的两个教程

但我还是停留在第二个教程上——配置UserManager。下面这句话对我不适用:

    // configure the user manager
    UserManagerFactory = () =>
    {
        var usermanager = new UserManager<AppUser>(
            new UserStore<AppUser>(new AppDbContext()));
        ...
    }
并向我显示以下消息:

参数类型“MyProject.DbContext.AppDbContext”不可分配给参数类型“System.Data.Entity.DbContext”

我不明白为什么它在我的解决方案中不起作用,因为我完全遵循了教程。我的AppDbContext看起来像:

namespace MyProject.DbContext
{
    using MyProject.Models;

    using Microsoft.AspNet.Identity.EntityFramework;

    public class AppDbContext : IdentityDbContext<User>
    {
        public AppDbContext()
            : base("DefaultConnection")
        {
        }
    }
}
我还从Ben那里下载了源代码,并尝试运行它,它运行起来没有任何问题。我认为我所有的文件都不在同一个文件夹中没有任何区别

我希望你能帮助我。如果一个简单的教程不能正常工作,那真的很令人沮丧


关于,winklerrr

您的
UserManager
AppUser
作为泛型类型:
UserManager
,当您的数据库上下文将
User
作为泛型参数时
AppUser
User
是不同的类


您的用户定义类在任何地方都应该是相同的。

我通过删除与owin和ASP.net标识相关的所有引用并重新添加它们,解决了这个问题


我认为,这个问题是由引用的DLL和实际使用的DLL之间的差异引起的。。。(在package manager控制台中经常播放。)

在我看来,您的AppDbContext需要继承System.Data.Entity.DbContext,但这可能是一个接口,或者可能是基本实体上下文,尝试将AppDbContext:IdentityDbContext更改为AppDbContext:System.Data.Entity.DbContextAppDbContext继承自IdentityDbContext,后者继承自DbContext。这就是为什么我如此困惑…啊,是的,谢谢。。。但这并没有解决问题,对我来说也是如此。谢谢。我通过数据包管理器卸载/重新安装了EF 6.2,从而消除了错误
namespace MyProject.DbContext
{
    using MyProject.Models;

    using Microsoft.AspNet.Identity.EntityFramework;

    public class AppDbContext : IdentityDbContext<User>
    {
        public AppDbContext()
            : base("DefaultConnection")
        {
        }
    }
}
namespace MyProject.Models
{
    using Microsoft.AspNet.Identity.EntityFramework;

    public class User : IdentityUser
    {
        public string Name{ get; set; }
    }
}