Not sure what I am doing wrong and why it is creating double navigation for each table. I am reading the guidance from https://docs.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-3.1.
This has been driving me nuts and I need to resolve this before going live next week.
Any help would be much appreciated.
Entities:
public class AppUser : IdentityUser<long>
{
public bool HasResetPassword { get; set; }
public DateTime? LastLogIn { get; set; }
public DateTime? DateRegistered { get; set; }
public DateTime? RegistrationDate { get; set; }
public override string ToString()
{
return UserName;
}
public virtual ICollection<AppUserClaim> Claims { get; set; }
public virtual ICollection<AppUserLogin> Logins { get; set; }
public virtual ICollection<AppUserToken> Tokens { get; set; }
public virtual ICollection<AppUserRole> UserRoles { get; set; }
}
public class AppRole : IdentityRole<long>
{
public string Description { get; set; }
public virtual ICollection<AppUserRole> UserRoles { get; set; }
public override string ToString()
{
return $"{Name} - {Description}";
}
}
public class AppUserRole : IdentityUserRole<long>
{
public virtual AppUser User { get; set; }
public virtual AppRole Role { get; set; }
}
public class AppUserClaim : IdentityUserClaim<long>
{
public virtual AppUser User { get; set; }
}
public class AppUserLogin : IdentityUserLogin<long>
{
public virtual AppUser User { get; set; }
}
public class AppRoleClaim : IdentityRoleClaim<long>
{
public virtual AppRole Role { get; set; }
}
public class AppUserToken : IdentityUserToken<long>
{
public virtual AppUser User { get; set; }
}
I believe you are doing useless work, what would you like to achieve? what is the double foreign key for?
if you just want to add columns to security tables, follow this post it is written in a simple and precise way:
How to add Custom User Properties in Identity Membership System
this is a small example:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
namespace Identity.Models
{
public class AppUser : IdentityUser
{
public Country Country { get; set; }
public int Age { get; set; }
[Required]
public string Salary { get; set; }
}
public enum Country
{
USA, UK, France, Germany, Russia
}
}