using FastEndpoints; using FastEndpoints.Swagger; using Microsoft.EntityFrameworkCore; using PyroFetes; var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); builder.Services.AddFastEndpoints(); builder.Services.SwaggerDocument(); var app = builder.Build(); using (var scope = app.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); db.Database.ExecuteSqlRaw(""" IF EXISTS ( SELECT 1 FROM sys.foreign_keys WHERE name = 'FK_Shows_Cities_CityId' AND parent_object_id = OBJECT_ID('Shows') ) ALTER TABLE Shows DROP CONSTRAINT FK_Shows_Cities_CityId """); db.Database.ExecuteSqlRaw(""" IF COL_LENGTH('Shows', 'CityId') IS NOT NULL AND COLUMNPROPERTY(OBJECT_ID('Shows'), 'CityId', 'AllowsNull') = 0 ALTER TABLE Shows ALTER COLUMN CityId INT NULL """); } if (app.Environment.IsDevelopment()) { app.UseSwaggerGen(); } app.UseHttpsRedirection(); app.UseFastEndpoints(); app.Run();