Как изменить тип Первичного Ключа со string на int в модели User наследуемой от IdentityUser в ASP.NET MVC?
Не могу изменить первичный ключ в модели наследуемой от IdentityUser
в ASP.NET MVC. Я создаю только условного IdentityUser
, без кастомных ролей и не могу никак поменять тип создаваемого Первичного Ключа, возникает ошибка из-за несоответствия Первичного и Внешнего ключей.
При создании миграции выдаёт ошибку:
The relationship from 'Club.AppUser' to 'AppUser.Clubs' with foreign key properties {'AppUserId' : int?} cannot target the primary key {'Id' : string} because it is not compatible. Configure a principal key or a set of foreign key properties with compatible types for this relationship.
Когда навожу на Id
в классе AppUser
выдаёт:
AppUser.id скрывает наследуемый член Identity< string >.id. Чтобы текущий член перевыполнял операцию добавите ключевое слово override
и это тоже пробовал.
Буду очень благодарен за любую помощь.
Части кода для понимания проблемы:
using Microsoft.AspNetCore.Identity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public class AppUser : IdentityUser
{
[Key]
public int Id { get; set; }
public int? Pace { get; set; }
public int? Mileage { get; set; }
public string? ProfileImageUrl { get; set; }
public string? City { get; set; }
public string? State { get; set; }
[ForeignKey("Address")]
public int? AddressId { get; set; }
public Address? Address { get; set; }
public ICollection<Club> Clubs { get; set; }
public ICollection<Race> Races { get; set; }
}
Именно в AppUser
и нужно изменить тип на int
public class Race
{
[Key]
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string? Image { get; set; }
public DateTime? StartTime { get; set; }
public int? EntryFee { get; set; }
public string? Website { get; set; }
public string? Twitter { get; set; }
public string? Facebook { get; set; }
public string? Contact { get; set; }
[ForeignKey("Address")]
public int? AddressId { get; set; }
public Address Address { get; set; }
public RaceCategory RaceCategory { get; set; }
[ForeignKey("AppUser")]
public int? AppUserId { get; set; }
public AppUser? AppUser { get; set; }
}
public class Club
{
[Key]
public int Id { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? Image { get; set; }
[ForeignKey("Address")]
public int? AddressId { get; set; }
public Address? Address { get; set; }
public ClubCategory ClubCategory { get; set; }
[ForeignKey("AppUser")]
public int? AppUserId { get; set; }
public AppUser? AppUser { get; set; }
}
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : IdentityDbContext<AppUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<Race> Races { get; set; }
public DbSet<Club> Clubs { get; set; }
public DbSet<Address> Addresses { get; set; }
}