zoukankan      html  css  js  c++  java
  • Entity Framework Core 3.1 学习笔记10 在 ASP.NET Core 中配置 EF Core

    democontext:

      public DemoContext(DbContextOptions<DemoContext> options):base(options) {
               
            }

    nuget包:

        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />

    Startup

     public void ConfigureServices(IServiceCollection services)
            {
                services.AddControllers();
                services.AddDbContext<DemoContext>(options => {
                    options.UseSqlServer(Configuration.GetConnectionString("LocalDb"));
                });
            }

    appsettings.json添加连接字符串:

    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "ConnectionStrings": {
        "LocalDb": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Demo;"
      },
      "AllowedHosts": "*"
    }
    

      

  • 相关阅读:
    type和object详解
    元类+单例
    单表查询和多表查询
    外键
    存储引擎,MySQL中的数据类型及约束
    壹拾壹




  • 原文地址:https://www.cnblogs.com/tofight/p/14646056.html
Copyright © 2011-2022 走看看