本文介绍了不支持每个类型的多个对象集。该对象集“ApplicationUsers”和“用户”可以同时包含类型ApplicationUser的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我停留在一个奇怪的问题。

我学习MVC 5和几乎所有由内置的模板创建的。
我只加一类历史

 公共类历史
{
    [键]
    公众的DateTime日期{搞定;组; }    公共虚拟ApplicationUser用户{搞定;组; }    公共字符串ITEMNAME {搞定;组; }}

和内部内置ApplicationUser:

 公共类ApplicationUser:IdentityUser
    {
        公共异步任务< ClaimsIdentity> GenerateUserIdentityAsync(的UserManager< ApplicationUser>经理)
        {
            //注意authenticationType必须CookieAuthenticationOptions.AuthenticationType定义的匹配
            VAR的UserIdentity =等待manager.CreateIdentityAsync(这一点,DefaultAuthenticationTypes.ApplicationCookie);
            //添加自定义的用户在这里声明
            返回的UserIdentity;
        }        公共虚拟的ICollection<历史与GT;历史{搞定;组; }
    }

下面是错误消息:

 每种类型的多个对象集,不支持。该对象集ApplicationUsers和用户可以同时包含类型'MyOnlineShopping.Models.ApplicationUser的实例。    说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。    异常详细信息:System.InvalidOperationException:每种类型的多个对象集,不支持。该对象集ApplicationUsers和用户可以同时包含类型'MyOnlineShopping.Models.ApplicationUser的实例。    源错误:
    124线:{
    125线:VAR用户=新ApplicationUser(){用户名= model.Email,电子邮件= model.Email};
    126线:IdentityResult结果=等待UserManager.CreateAsync(用户,model.Password);
    127线:如果(result.Succeeded)
    128线:{
源文件:F:\\职场\\ MyOnlineShopping \\ MyOnlineShopping \\ \\控制器线AccountController.cs:126


解决方案

我最终重新命名为ApplicationUser用户,rescaffolding一切都奇迹般地开始工作。

看起来像模板是有点不怪人。

I am stuck at an odd issue.

I am learning MVC 5 and almost everything is created by the built-in template.I only added a class History

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

    public virtual ApplicationUser User { get; set; }

    public string ItemName { get; set; }

}

And inside the built-in 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; }
    }

Here is the error message:

 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 
解决方案

I ended up renaming ApplicationUser to User, rescaffolding and everything magically started working.

Looks like the templates are a bit out of wack.

这篇关于不支持每个类型的多个对象集。该对象集“ApplicationUsers”和“用户”可以同时包含类型ApplicationUser的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 20:16