【问题标题】:C# The base virtual properties of IdentityUser are not visibleC# IdentityUser 的基本虚拟属性不可见
【发布时间】:2019-08-21 08:01:12
【问题描述】:

我创建了一个继承自 Microsoft.AspNet.Identity.EntityFramework 的 AppUser 类,看起来像下面的代码,但除非我覆盖它们,否则 IdentityUser 的基本属性不可见? IdentityUser 的公共虚拟字段不应该通过 AppUser 类的继承来访问吗?

这发生在一个“类”项目中,输出是一个针对 .Net 4.6.2 的 DLL,我认为我拥有所有必需的包。我可以使用 AppUser 类;创建用户,创建角色,将用户添加到角色等。只是无法弄清楚为什么继承的行为在这里与我的其他项目中的工作方式不同?

public class AppUser : IdentityUser
{
    // why do I need to override these to get access to them
    public override string Id { get => base.Id; set => base.Id = value; }
    public override string Email { get => base.Email; set => base.Email = value; }
    public override string UserName { get => base.UserName; set => base.UserName = value; }
    public override string PasswordHash { get => base.PasswordHash; set => base.PasswordHash = value; }

    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }

    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public DateTime CreateDate { get; set; }

}

【问题讨论】:

  • 您应该将其发布为答案,因为它是正确的。为了跟进,缺少的字段位于调用类/DLL 项目的控制台项目中。当我将 Identity.Framework 包添加到控制台项目时,虚拟字段在调用者项目中变得可见。谢谢。

标签: c# asp.net-identity virtual


【解决方案1】:

您必须通过添加 NuGet 包 Microsoft.AspNet.Identity.EntityFramework 在项目中引用 Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll,因为这是声明这些属性的位置。仅引用声明了AppUser 的DLL 是不够的。

【讨论】:

    猜你喜欢
    • 2012-06-17
    • 2016-07-05
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 2011-01-18
    • 1970-01-01
    相关资源
    最近更新 更多