asp.net – 不支持每种类型的多个对象集.对象集’ApplicationUsers’和’Users’都可以包含ApplicationUser类型的实例

我陷入了一个奇怪的问题.

我正在学习MVC 5,几乎所有内容都是由内置模板创建的.
我只添加一个类历史

public class History
{
    [Key]
    public DateTime Date { get; set; }

    public virtual ApplicationUser User { get; set; }

    public string ItemName { get; set; }

}

在内置的ApplicationUser中:

public class ApplicationUser : IdentityUser
    {
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationoptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }

        public virtual ICollection<History> Histories { get; set; }
    }

这是错误消息:

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

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: system.invalidOperationException: Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'MyOnlineshopping.Models.ApplicationUser'.

    Source Error: 


    Line 124:            {
    Line 125:                var user = new ApplicationUser() { UserName = model.Email,Email = model.Email };
    Line 126:                IdentityResult result = await UserManager.CreateAsync(user,model.Password);
    Line 127:                if (result.Succeeded)
    Line 128:                {
Source File: f:\Workplace\MyOnlineshopping\MyOnlineshopping\Controllers\AccountController.cs    Line: 126

解决方法

我最终将ApplicationUser重命名为User,重新加载,一切都神奇地开始工作.

看起来模板有点出没了.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....