asp.net - ASP.NET 无法访问角色表中的新字段
问题描述
我刚刚扩展了我的 AspNetRoles 表,如下所示:
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public String ApplicationId { get; set; }
public AspNetApplications Application { get; set; }
}
当我添加我的迁移并更新数据库时,出现了 ApplicationId 和一个鉴别器列。
但是,当我需要访问该表中的数据时,我似乎无法访问新字段:
List<ApplicationRole> data = (from ar in dbContext.Roles
join a in dbContext.AspNetApplications
on ar.ApplicationId equals a.Id
select new ApplicationRole
{
Id = ar.Id,
Name = ar.Name
ApplicationId = (Unable to access this section)
}).ToList();
我已经尝试按照本教程http://johnatten.com/2014/06/22/asp-net-identity-2-0-customizing-users-and-roles/#Extending-Identity-Role并添加了一个新的我的 IdentityConfig 中的 ApplicationRoleManager
public class ApplicationRoleManager : RoleManager<ApplicationRole>
{
public ApplicationRoleManager(IRoleStore<ApplicationRole, string> roleStore): base(roleStore)
{
}
public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context)
{
return new ApplicationRoleManager(new RoleStore<ApplicationRole>(context.Get<ApplicationDbContext>()));
}
}
当我为我的数据库播种时,ApplicationId 被填满没有问题。只有当我尝试从中获取数据时才会遇到问题。
解决方案
听起来很傻,但是你能检查一下你是否已经在另一个命名空间中定义了 ApplicationRole 类,也许你想要填充的那个来自另一个你没有定义 ApplicationId 的命名空间
select new ApplicationRole
{
Id = ar.Id,
Name = ar.Name , //or maybe because you do not have a comma after ar.Name
ApplicationId = (Unable to access this section)
}).ToList();
推荐阅读
- r - 如何用鼠标R仅估算一列或几列
- c# - 在离线 PC 上的 Visual Studio 2012 中启用 C# 6.0
- matlab - 重命名符号变量 - Matlab
- c# - Newtonsoft C# 自定义 JsonConverter 不反序列化字节数组
- php - 在下一个中插入一个 id 属性
在 PHP 中的字符串中标记
- python - 我无法在 Python/Windows 中导入模块
- angular - 无法使用 ngx-indexed-db 将数据从 indexedDB 传递到 Angular Subject 以在 Observable 中使用
- javascript - 检查数组是否包含正确偏移量中的数组
- c# - IOptions 与不匹配的属性名称绑定
- angular - 可观察的构造函数被传递变量并在调用中使用