小编Lor*_*fur的帖子

如何在 EF Core 中创建 DbContext 实例时传递 DbContextOptions 值

我试图从appSettings.json文件中获取连接字符串,但我不能。

我的启动是这样的:

namespace YangSoft_WebAPI
{
    public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional:false, reloadOnChange:true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional:true)
                .AddEnvironmentVariables();

            Configuration = builder.Build();
            var enviroment = Configuration["ApplicationSettings:Enviroment"];

        }
        readonly string AllowControlOrigins = "Access-Control-Allow-Origin";

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettingsDAL>(Configuration.GetSection("ApplicationSettings"));
            services.AddDbContextPool<yangsoftDBContext>(options =>
                     options.UseSqlServer(Configuration.GetConnectionString("local")));
            services.AddCors(options =>
            {

                options.AddDefaultPolicy(
                builder =>
                {
                    builder.WithOrigins("*"); …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core

2
推荐指数
1
解决办法
3293
查看次数

标签 统计

asp.net-core ×1

c# ×1

entity-framework-core ×1