<tfoot id='S5rgp'></tfoot>
    • <bdo id='S5rgp'></bdo><ul id='S5rgp'></ul>

  • <small id='S5rgp'></small><noframes id='S5rgp'>

    <legend id='S5rgp'><style id='S5rgp'><dir id='S5rgp'><q id='S5rgp'></q></dir></style></legend>

  • <i id='S5rgp'><tr id='S5rgp'><dt id='S5rgp'><q id='S5rgp'><span id='S5rgp'><b id='S5rgp'><form id='S5rgp'><ins id='S5rgp'></ins><ul id='S5rgp'></ul><sub id='S5rgp'></sub></form><legend id='S5rgp'></legend><bdo id='S5rgp'><pre id='S5rgp'><center id='S5rgp'></center></pre></bdo></b><th id='S5rgp'></th></span></q></dt></tr></i><div id='S5rgp'><tfoot id='S5rgp'></tfoot><dl id='S5rgp'><fieldset id='S5rgp'></fieldset></dl></div>
      1. Entity Framework Core 2.0 添加迁移不生成任何东西

        时间:2023-05-22
        <tfoot id='OaSEw'></tfoot>

          <tbody id='OaSEw'></tbody>
        <i id='OaSEw'><tr id='OaSEw'><dt id='OaSEw'><q id='OaSEw'><span id='OaSEw'><b id='OaSEw'><form id='OaSEw'><ins id='OaSEw'></ins><ul id='OaSEw'></ul><sub id='OaSEw'></sub></form><legend id='OaSEw'></legend><bdo id='OaSEw'><pre id='OaSEw'><center id='OaSEw'></center></pre></bdo></b><th id='OaSEw'></th></span></q></dt></tr></i><div id='OaSEw'><tfoot id='OaSEw'></tfoot><dl id='OaSEw'><fieldset id='OaSEw'></fieldset></dl></div>

              • <bdo id='OaSEw'></bdo><ul id='OaSEw'></ul>

                  <small id='OaSEw'></small><noframes id='OaSEw'>

                • <legend id='OaSEw'><style id='OaSEw'><dir id='OaSEw'><q id='OaSEw'></q></dir></style></legend>
                  本文介绍了Entity Framework Core 2.0 添加迁移不生成任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我是 EF 新手,正在尝试使用 VS 2017、.NET Core 2.0 和 EF 2.0 创建一个简单的测试解决方案,但我无法 add-migration 来创建迁移文件夹以及初始迁移.

                  I'm new to EF and am trying to create a simple test solution using VS 2017, .NET Core 2.0 and EF 2.0 but I can't get add-migration to create the migrations folder and the initial migration.

                  我创建了一个名为 Driver 的解决方案,其中包含两个 .Net Core 类库项目:

                  I have created a solution called Driver with two .Net Core class library projects:

                  Driver.Data
                  Driver.Domain
                  

                  Driver.Data中安装了以下包:

                  Microsoft.EntityFrameworkCore.SqlServer
                  Microsoft.EntityFrameworkCore.Tools
                  

                  Driver.Data 有一个名为 Driver.Context 的 cs 文件:

                  Driver.Data has a single cs file called Driver.Context:

                  using Driver.Domain;
                  using Microsoft.EntityFrameworkCore;
                  
                  namespace Driver.Data
                  {
                      public class DriverContext : DbContext
                      {
                          public DbSet<Company> Companies { get; set; }
                  
                          protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
                          {
                              optionsBuilder.UseSqlServer(
                                  "Server=(localdb)\mssqllocaldb; Database=Driver; Trusted_Connection=True;"
                                  );
                          }
                      }
                  
                  }
                  

                  Driver.Domain 有一个名为 Company.cs 的 cs 文件:

                  Driver.Domain has a single cs file called Company.cs:

                  namespace Driver.Domain
                  {
                      public class Company
                      {
                          public int Id { get; set; }
                          public string Name { get; set; }
                          public string City { get; set; }
                          public string State { get; set; }
                      }
                  }
                  

                  我已将启动项目设置为 Driver.Data,并在 PM 控制台中将默认项目设置为 Driver.Data

                  I've set the startup project to Driver.Data and in the PM Console I've set the Default Project to Driver.Data

                  这是add-migration init -verbose的输出:

                  Using project 'Driver.Data'.
                  Using startup project 'Driver.Data'.
                  Build started...
                  Build succeeded.
                  C:Program Filesdotnetdotnet.exe exec --depsfile "C:Usersalex.florinDocumentsVisual Studio 2017ProjectsDriver	runkDriver.DatainDebug
                  etcoreapp2.0Driver.Data.deps.json" --additionalprobingpath C:Usersalex.florin.nugetpackages --additionalprobingpath "C:Program Files (x86)Microsoft SDKsNuGetPackagesFallback" --additionalprobingpath "C:Program FilesdotnetsdkNuGetFallbackFolder" --fx-version 2.0 "C:Program FilesdotnetsdkNuGetFallbackFoldermicrosoft.entityframeworkcore.tools2.0.1	ools
                  etcoreapp2.0ef.dll" migrations add init --json --verbose --no-color --prefix-output --assembly "C:Usersalex.florinDocumentsVisual Studio 2017ProjectsDriver	runkDriver.DatainDebug
                  etcoreapp2.0Driver.Data.dll" --startup-assembly "C:Usersalex.florinDocumentsVisual Studio 2017ProjectsDriver	runkDriver.DatainDebug
                  etcoreapp2.0Driver.Data.dll" --project-dir "C:Usersalex.florinDocumentsVisual Studio 2017ProjectsDriver	runkDriver.Data\" --root-namespace Driver.Data
                  

                  没有错误,但没有生成任何内容.

                  There are no errors but nothing is being generated.

                  推荐答案

                  @JulieLerman 在我的复数视觉课程讨论中提供了答案.尝试使用 .NET Core 类库显然存在问题.成功的解决方法是将以下内容放在 DBContext 项目的 csproj 文件中:

                  @JulieLerman provided the answer when I asked in her pluralsight course discussion. There is apparently an issue with attempting this with the .NET Core class libraries. The successful workaround is to put the following in the csproj file of the DBContext project:

                  <PropertyGroup>
                    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> 
                  </PropertyGroup>
                  

                  她为此写了一篇博客:http://thedatafarm.com/data-access/the-secret-to-running-ef-core-2-0-migrations-from-a-net-core-or-网络标准类库/

                  She wrote a blog about it: http://thedatafarm.com/data-access/the-secret-to-running-ef-core-2-0-migrations-from-a-net-core-or-net-standard-class-library/

                  另外,一定要把里面有DBContext的项目设置为启动项目

                  Additionally, be sure to set the project with the DBContext in it as the startup project

                  这篇关于Entity Framework Core 2.0 添加迁移不生成任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Visual Studio Community 2017 上禁用 Visual Studio 托管进程 下一篇:Visual Studio 2017 在应用程序设置中找不到连接字符串

                  相关文章

                  <tfoot id='Rhmfu'></tfoot>
                • <small id='Rhmfu'></small><noframes id='Rhmfu'>

                  <i id='Rhmfu'><tr id='Rhmfu'><dt id='Rhmfu'><q id='Rhmfu'><span id='Rhmfu'><b id='Rhmfu'><form id='Rhmfu'><ins id='Rhmfu'></ins><ul id='Rhmfu'></ul><sub id='Rhmfu'></sub></form><legend id='Rhmfu'></legend><bdo id='Rhmfu'><pre id='Rhmfu'><center id='Rhmfu'></center></pre></bdo></b><th id='Rhmfu'></th></span></q></dt></tr></i><div id='Rhmfu'><tfoot id='Rhmfu'></tfoot><dl id='Rhmfu'><fieldset id='Rhmfu'></fieldset></dl></div>

                  <legend id='Rhmfu'><style id='Rhmfu'><dir id='Rhmfu'><q id='Rhmfu'></q></dir></style></legend>
                        <bdo id='Rhmfu'></bdo><ul id='Rhmfu'></ul>