Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用ApplicationUser的子类_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# 如何使用ApplicationUser的子类

C# 如何使用ApplicationUser的子类,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,在我的模型中,有两个类继承自ApplicationUser public class ApplicationUser : IdentityUser { [DataType(DataType.MultilineText)] public string SelfIntroduction { get; set; } } public class Author : ApplicationUser { public ICollection<Paper> Uploaded

在我的模型中,有两个类继承自ApplicationUser

public class ApplicationUser : IdentityUser
{
    [DataType(DataType.MultilineText)]
    public string SelfIntroduction { get; set; }
}
public class Author : ApplicationUser
{
    public ICollection<Paper> UploadedPapers { get; set; }
}
public class PCMember : ApplicationUser
{
    public int? Quota { get; set; }
    public ICollection<Topic> PreferredTopics { get; set; }
}

这意味着我使用了一个错误的UserManager或其他东西?

我可能找到了一个解决方案,但不是100%确定使用自定义UserManager

public UserManager<Author> AuthorManager { get; private set; }

public UserManager<PCMember> PCMemberManager { get; private set; }

但是,我之所以说它不是100%确定,是因为在我的AspNetUsers表中,用户的鉴别器列是ApplicationUser,我将其更改为PCMember,然后它就工作了

检查这里@barry,问题是我无法生成ApplicationUser子类的实例,而不是如何存储它们。我将TPH用于我的用户模型。如果我把username传递给参数,我可以得到ApplicationUser,但不能得到PCMember,这就是我需要的。谢谢你的回答,Alex。如何实例化PCMemberManager?它使用DI吗?
    "Additional information: Unable to cast object of type 
'System.Data.Entity.DynamicProxies.ApplicationUser_XXX' to type 
'PaperReviewSystem.Models.PCMember'."
public UserManager<Author> AuthorManager { get; private set; }

public UserManager<PCMember> PCMemberManager { get; private set; }
PCMember user = PCMemberManager.FindByNameAsync(User.Identity.Name).Result;