질문&답변
Unable to create an object of type 'ApplicationDbContext'
using Microsoft.EntityFrameworkCore; using WebApi.Data; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); // .NET Core 최신버전용 AddDbContext 방법. builder.Services.AddDbContext (options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/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.MapRazorPages(); app.Run(); .NET Core의 최신 버전에서는 Startup이 더이상 사용되지 않아서 말씀하신대로 Program.cs에 다음과 같이 입력하여 처리하면 됩니다. 영상과 똑같이 하셨더라면, 상단에 using을 다음과 같이 작성해주시면 됩니다. using Microsoft.EntityFrameworkCore; using WebApi.Data; 이 후 UsesSqlServer가 또 말썽일텐데 이는 강의에서 보신 것처럼 Microsoft.EntityFrameworkCore.sqlserver 설치하면 문제없이 진행됩니다~!
- 좋아요수
- 0
- 댓글수
- 2
- 조회수
- 676





