使用entity framework core时报如标题错误。

在startup.cs文件中配置服务

public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
 
            //注册数据库上下文
            services.AddEntityFrameworkSqlServer().AddDbContext<SQLDbRWContext>(options =>
            {
                options.UseSqlServer(Configuration.GetConnectionString("Main_ReadAndWrite"));
            });
        }

解决方案

1、首先检查项目添加了Microsoft.EntityFrameworkCore和Microsoft.EntityFrameworkCore.SqlServer引用

2、需要手动在startup.cs中添加引用,不然无法识别扩展方法。

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;

 

唉,有点坑。

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-03
  • 2022-02-26
  • 2021-12-10
  • 2022-12-23
  • 2022-01-20
  • 2021-09-30
  • 2022-12-23
相关资源
相似解决方案