Почему я получаю эту ошибку:
Частичные объявления 'ApplicationDbContext' не должны указывать разные базовые классы
Пожалуйста, смотрите мой код ниже:
using System;
using System.ComponentModel.DataAnnotations;
using IssueTracker.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace IssueTracker.Data
{
public class ApplicationUser: IdentityUser
{
[Required]
[MaxLength(100)]
public string FistName { get; set; }
[MaxLength(100)]
public string MiddleName { get; set; }
[Required]
[MaxLength(100)]
public string LastName { get; set; }
public bool IsActivated { get; set; } = false;
public DateTime DateAdded { get; set; } = DateTime.Now;
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) {}
// Creating the roles
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ApplicationUser>().ToTable("User");
builder.Entity<IdentityRole>().ToTable("Role");
builder.Entity<IdentityUserRole<string>>().ToTable("UserRole");
builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaim");
builder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin");
builder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaim");
builder.Entity<IdentityUserToken<string>>().ToTable("UserToken");
builder.Entity<IdentityRole>().HasData(
new { Id = "1", name="Admin", NoralizeName = "ADMIN" },
new { Id = "2", name="Customer", NoralizeName = "CUSTOMER" },
new { Id = "3", name="Moderator", NoralizeName = "MODERATOR" }
);
}
public DbSet<ProductModel> Products { get; set; }
}
}
Я использую Identity Framework и пытаюсь переименовать имена таблиц по умолчанию.
Если я использую это:
public class ApplicationDbContext : IdentityDbContext<IdentityUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) {}
...
Я не получаю никакой ошибки, но не могу переименовать
builder.Entity (). ToTable ("Пользователь ");
Это просто дает мне AspNetUsers
Можете ли вы помочь мне с этим?Спасибо.
РЕДАКТИРОВАТЬ После добавления предложенного решения я все еще не мог переименовать AspNetUser в User.Пожалуйста, смотрите миграцию ниже:
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
UserId = table.Column<string>(nullable: false),
UserName = table.Column<string>(maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
Email = table.Column<string>(maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
PasswordHash = table.Column<string>(nullable: true),
SecurityStamp = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
TwoFactorEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
LockoutEnabled = table.Column<bool>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
Discriminator = table.Column<string>(nullable: false),
FistName = table.Column<string>(maxLength: 100, nullable: true),
MiddleName = table.Column<string>(maxLength: 100, nullable: true),
LastName = table.Column<string>(maxLength: 100, nullable: true),
IsActivated = table.Column<bool>(nullable: true),
DateAdded = table.Column<DateTime>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.UserId);
});