微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Linux 上的 C# DotNet 实体框架核心迁移错误

如何解决Linux 上的 C# DotNet 实体框架核心迁移错误

我在 Linux 上使用 JetBrains Rider。每当我运行 //--- style ----// .mapBoxgl-ctrl-geocoder { font-size: 18px; line-height: 24px; font-family: "Open Sans","Helvetica Neue",Arial,Helvetica,sans-serif; position: relative; background-color: #fff; width: 100%; min-width: 240px; z-index: 1; border-radius: 4px; transition: width .25s,min-width .25s; right: 900px; visibility: hidden; } .mapBoxgl-ctrl-geocoder .show { visibility: visible; } //----- javascript code ------// function search() { let el_mapBoxgl = document.getElementsByClassName('mapBoxgl-ctrl-geocoder')[0]; el_mapBoxgl.className += " show"; } 时,它都会在终端中执行此操作并给我以下错误

dotnet ef migrations add InitialCreate

如果有人知道答案,谢谢!

解决方法

我在 .net 5 Web API 项目中遇到了同样的问题

EF 工具查看 CreateWebHostBuilder 方法并在找不到时返回错误。

directories:

/src 
    |-- /YourPorject.Infrastructure
    |-- /YourPorject.API

public static IHostBuilder CreateWebHostBuilder(string[] args)
{
    return Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((context,config) =>
            {
                config.AddJsonFile(
                    context.HostingEnvironment.ContentRootPath + $"/Config/appsettings-dev.json",false,false);
            })
            .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}

使用bash创建和更新数据库

    cd src/
    dotnet ef migrations add Init 
    --project YourPorject.Infrastructure/YourPorject.Infrastructure.csproj  
    --startup-project YourPorject.API/YourPorject.API.csproj 
    -o ./Repositories/Migrations/

    cd src/
    dotnet ef database update 
    --project YourPorject.Infrastructure/YourPorject.Infrastructure.csproj 
    --startup-project YourPorject.API/YourPorject.API.csproj

使用这个包(很重要

<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.8" />
</ItemGroup>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。