初始化dbModel上下文时出现错误,如下所示:这是我的dbContext课:public class DbModel : DbContext{ public DbModel() { } public DbModel(DbContextOptions<DbModel> options) : base(options) { } public DbSet<UserModel> User {get;set;}}我根据stackoverflow中的一些答案在ConfigureServices方法中添加了以下代码Startup.cs,但是仍然出现错误。services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();这是我的ConfigureServices方法:public void ConfigureServices(IServiceCollection services){ services.AddMvc(); var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNetCore.Restaurant;Trusted_Connection=True;ConnectRetryCount=0"; services.AddDbContext<DbModel>(options => options.UseSqlServer(connection)); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Restaurant APIs", Description = "Swagger Core API" }); }); services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton<IActionContextAccessor, ActionContextAccessor>(); }可能是什么原因?
- 2 回答
- 0 关注
- 219 浏览
添加回答
举报
0/150
提交
取消