ASP.NET Identity - 不支持每种类型的多个对象集 [英] ASP.NET Identity - Multiple object sets per type are not supported

查看:25
本文介绍了ASP.NET Identity - 不支持每种类型的多个对象集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用 ASP.NET Identity 时出错.

I got an error using ASP.NET Identity in my app.

不支持每种类型的多个对象集.对象集身份用户"和用户"都可以包含类型的实例'推荐平台.Models.ApplicationUser'.

Multiple object sets per type are not supported. The object sets 'Identity Users' and 'Users' can both contain instances of type 'Recommendation Platform.Models.ApplicationUser'.

我在 StackOverflow 中看到了一些有关此错误的问题.都表示在两个相同类型的 DbSet 对象上.但是在我的 DbContext 中没有相同类型的 DbSets.登录期间 FindAsync() 方法抛出异常.

I saw a few questions about this error in StackOverflow. All indicate on two DbSet objects of the same type. But in my DbContext there aren't the same types of DbSets. Exception is thrown on FindAsync() method during logging in.

if (ModelState.IsValid)
    var user = await UserManager.FindAsync(model.UserName, model.Password);
    if (user != null && user.IsConfirmed)
    {

问题是我没有两个相同类型的 DbSets.我的上下文如下所示:

The problem is I don't have two DbSets of the same type. My Contexts look like this:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }

    public System.Data.Entity.DbSet<RecommendationPlatform.Models.ApplicationUser> IdentityUsers { get; set; }

}

public class RecContext : DbContext
{
    public RecContext()
        : base("RecConnection")
    {
        Database.SetInitializer<RecContext>(new DropCreateDatabaseIfModelChanges<RecContext>());
    }

    public DbSet<Recommendation> Recommendations { get; set; }
    public DbSet<Geolocation> Geolocations { get; set; }
    public DbSet<Faq> Faqs { get; set; }
    public DbSet<IndexText> IndexTexts { get; set; }
}

是什么导致了这个问题?也许与内置的 ASP.NET Identity 功能有关?无论如何,什么是 Users 类型?我的应用程序中没有它...

What could cause this problem? Maybe something connected with in-built ASP.NET Identity functionalities? Anyway, what is Users type? I don't have it in my app...

推荐答案

您确实有两个相同类型的 DbSets`.

You do have two DbSets` of the same type.

IdentityDbContext 本身包含声明为的 Users 属性:

IdentityDbContext<T> itself contains Users property declared as:

public DbSet<T> Users { get; set; }

你在课堂上宣布第二个.

You're declaring second one in your class.

这篇关于ASP.NET Identity - 不支持每种类型的多个对象集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆