实体框架核心:DbContextOptionsBuilder不包含"usesqlserver"的定义,也不包含扩展方法"usesqlserver"

编程入门 行业动态 更新时间:2024-10-20 09:25:20
本文介绍了实体框架核心:DbContextOptionsBuilder不包含"usesqlserver"的定义,也不包含扩展方法"usesqlserver"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是EF Core的新手,我正在尝试使其与我的ASP.NET Core项目一起使用.

I am new to EF core and I'm trying to get it to work with my ASP.NET Core project.

尝试将DbContext配置为使用config中的连接字符串时,在startup.cs中收到上述错误.我正在学习本教程: docs.microsoft /en-us/aspnet/core/data/ef-mvc/intro

I get the above error in my startup.cs when trying configure the DbContext to use a connection string from config. I am following this tutorial: docs.microsoft/en-us/aspnet/core/data/ef-mvc/intro

startup.cs中的有问题的代码:

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore; using tracV2.models; using tracV2.data; namespace tracV2 { public class Startup { // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddSingleton<IConfiguration>(Configuration); string conn = Configuration.GetConnectionString("optimumDB"); services.AddDbContext<tracContext>(options => options.usesqlserver(conn)); }

如果将UseSqlServer方法直接放在上下文中,则可以识别该方法:

The UseSqlServer method is recognized if I put it directly into the context:

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; namespace tracV2.data { public class tracContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer("myrealconnectionstring"); }

我在网上进行的所有研究都指向缺少参考文献,但我似乎找不到我缺少的参考文献(查看图片).

All my research online points to missing references, but I can't seem to find out which one I am missing (see image).

推荐答案

这是项目系统中的一个已知问题.参见 dotnet/project-system#1741

This is a known issue in the project system. See dotnet/project-system#1741

更多推荐

实体框架核心:DbContextOptionsBuilder不包含"usesqlserver"的定义,也不包含扩展方法"usesq

本文发布于:2023-11-08 13:53:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也不   不包含   实体   框架   定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!