c# - 在 Visual Studio 上使用 Identity 创建新表和属性
问题描述
我正在尝试在默认身份表和我的默认身份表之间创建新表和关系,但是当我尝试使用 AccountController 上默认的“SignInManager.PasswordSignInAsync”方法登录时,我收到下面列出的错误:
- 无效的列名用户 ID
- 无效的列名用户 ID
- 无效的列名 RoleId
我为创建身份上下文所做的是检查项目启动时的选项,然后在 AspNetUser 表上创建额外的属性,我这样做:
public class ApplicationUser : IdentityUser
{
#region
public DateTime LastLoginDateTime { get; set; }
public string Name { get; set; }
public string Surnames { get; set; }
public string DNI { get; set; }
public string ProfileImageSource { get; set; }
#endregion
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Tenga en cuenta que el valor de authenticationType debe coincidir con el definido en CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Agregar aquí notificaciones personalizadas de usuario
return userIdentity;
}
}
然后我使用 Enable-Migrations 和 Update-Database。
直到这里一切正常,但是当我在同一个解决方案中使用另一个项目添加新表和关系(只是为了不混合我认为不好的上下文)与实体框架然后更新数据库时,我遇到了上面提到的问题。
注册新用户时工作正常,但是当调用“SignInManager.PasswordSignInAsync”方法时程序崩溃。
我不知道我在做什么错猜有人可以帮助我。
解决方案
我刚刚解决了这个问题。
我不知道为什么,但是如果我在 SQL Server 中从 0 创建数据库,而不是 Visual Studio EDMX 编辑器,它就可以完美运行。
如果您想解决与我相同的问题,请直接在 SQL Server 上进行更改。
推荐阅读
- asp.net - 哪种方式适合在没有 XSLT 的情况下使用 ASP.NET 控制台应用程序进行动态 XML 转换?
- python - 如何从数组中弹出整个项目?
- selenium - 如何使用硒单击两个选项卡中的一个链接?
- regex - 杨正则表达式
- moodle - Scorm 包仅标记为“完成”而不是“通过”
- windows - Spark-submit 不像 Intellij 那样运行代码
- python - 如何使用半指定的暗淡创建一个空的 numpy 数组?
- swift - SwiftUI中的NavigationView声明代码应该如何理解
- android - 无法在 Ionic 应用程序中打开移动相机
- r - 如何从整体中提取一部分数据框?