I use .net 6 and when I use Add an ASP.NET Core MVC controller with views, using Entity Framework Core(I do this in Area). I get an error.
I searched a lot but did not find any
error:
DBContext:
namespace PotLearn.DataLayer.Context
{
public class PotLearnContext:DbContext
{
public PotLearnContext(DbContextOptions<PotLearnContext> options)
: base(options)
{
}
#region User
public DbSet<User> Users { get; set; }
#endregion
}
}
program.cs:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
#region DataBase Context
var connectionString = builder.Configuration.GetConnectionString("PotLearnConnection");
builder.Services.AddDbContext<PotLearnContext>(options => options.UseSqlServer(connectionString));
#endregion
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
app.Run();
How can I fix this error?
Thankyou.