在.NET Core应用程序中使用现有的.NET身份数据库
我是身份核心的新手,并且正在尝试使用.NET Core 3.1.1创建MVC应用程序,并遇到身份障碍。
我最艰难的限制是我需要使用旧的MVC5应用程序中的旧身份数据库。该应用程序正在使用,这意味着无法更改表结构。
在启动中设置了Usermanager和模型:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("RaksaConnection")));
services.AddDbContext<RaksaDbContext>(options=>
options.UseSqlServer(
Configuration.GetConnectionString("RaksaConnection")));
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
//services.AddTransient <UserManager<ApplicationUser>>();
services.AddControllersWithViews();
services.AddRazorPages();
}
从较旧站点复制的模型:
public class ApplicationUser : IdentityUser
{
public ApplicationUser()
{
this.Id = Guid.NewGuid().ToString();
}
public string FirstName { get; set; }
public string LastName { get; set; }
private string PF_FName;
private string PF_FNameAndCompany;
public int? NeptonUserId { get; set; }
public string NeptonUserName { get; set; }
public int? NeptonUserPersonnelNumber { get; set; }
public virtual Guid CompanyDataId { get; set; }
public override string UserName { get; set; }
public override string NormalizedEmail { get { return this.Email.ToUpperInvariant(); } }
public override string NormalizedUserName { get { return this.UserName.ToUpperInvariant(); } }
public DateTime? LockoutEndDateUtc { get; set; }
private string PF_CompanyVat { get; set; }
private string PF_JobTitleValue { get; set; }
private DateTime PF_AccountCreated { get; set; }
public bool GIG_worker { get; set; }
public DateTime? LastLogin { get; set; }
public int CommLevelId { get; set; }
[Display(Name = "Nimi")]
public string FullName
{
get
{
this.PF_FName = FirstName + " " + LastName;
return this.PF_FName;
}
}
public DateTime AccountCreated
{
get
{
return this.PF_AccountCreated;
}
set
{
this.PF_AccountCreated = value;
}
}
private bool PF_Isrejected { get; set; }
public bool IsRejected
{
get
{
return this.PF_Isrejected;
}
set
{
this.PF_Isrejected = value;
}
}
public bool Active { get; set; }
public string JobTitle
{
get
{
return this.PF_JobTitleValue;
}
set
{
this.PF_JobTitleValue = value;
}
}
}
public class ApplicationRole : IdentityRole
{
public ApplicationRole()
{
base.Id = Guid.NewGuid().ToString();
}
public ApplicationRole(string name) : this()
{
base.Name = name;
}
public ICollection<Permission> Permissions { get; set; }
}
public class Permission
{
public Permission()
{
this.PermissionId = Guid.NewGuid().ToString();
this.RolesWithPermission = new HashSet<ApplicationRole>();
}
public string PermissionId { get; set; }
public string PermissionDescription { get; set; }
public ICollection<ApplicationRole> RolesWithPermission;
}
}
可以让Usermanager列出用户,列出用户的良好,但是SignManager compalains围绕归一化使用字段:
InvalidOperationException: The LINQ expression 'DbSet<ApplicationUser>
.Where(a => a.NormalizedUserName == __normalizedUserName_0)' could not be translated.
Either rewrite the query in a form that can be translated, or switch to client evaluation
explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(),
or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
不知道接下来要去哪里,我必须自定义SigninManager还是有一个更简单的解决方案?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论