Код: Выделить всё
The entity type 'IdentityUserToken' was first mapped explicitly and then ignored. Consider not mapping the entity type in the first place.
Код: Выделить всё
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("APIContextConnection") ?? throw new InvalidOperationException("Connection string 'APIContextConnection' not found.");
builder.Services.AddDbContext(options => options.UseNpgsql(connectionString));
builder.Services.AddIdentity(options => options.SignIn.RequireConfirmedAccount = false)
.AddEntityFrameworkStores();
// Add services to the container.
ServiceContainer.AddServices(builder.Services);
builder.Services.AddScoped();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Configure JWT authentication
var key = builder.Configuration["JWT:Key"];
if (string.IsNullOrEmpty(key))
throw new InvalidOperationException("JWT key not found.");
builder.Services.AddAuthentication(opt =>
{
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = builder.Configuration["JWT:Issuer"],
ValidAudience = builder.Configuration["JWT:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key))
};
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
}
Seed();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
void Seed()
{
using var scope = app.Services.CreateScope();
var dbSeeder = scope.ServiceProvider.GetRequiredService();
dbSeeder.Seed();
}
Код: Выделить всё
public class APIContext(DbContextOptions options) : IdentityDbContext(options)
{
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity().ToTable("User");
builder.Entity().ToTable("Role");
builder.Entity().ToTable("UserRoles");
builder.Ignore();
builder.Ignore();
builder.Ignore();
builder.Ignore();
}
// Entities
public DbSet User { get; set; }
}
Я пытался поместить base.OnModelCreating(builder); ниже всех builder.Ignore, но это не сработало.
p>
На самом деле я не получаю никаких ошибок, но каждый раз, когда я запускаю миграцию, я получаю эти предупреждения, и это очень раздражает
Подробнее здесь: https://stackoverflow.com/questions/783 ... s-in-net-8
Мобильная версия