Trying to set-up Entity Framework core in .Net Standard project

前端 未结 7 1526
耶瑟儿~
耶瑟儿~ 2020-12-14 00:39

I was wondering if I could set-up my EntityFrameworkCore in a .NET Standard 2.0 project easily. I was following this Tutorial but it requires either .NET Core or Framework.<

相关标签:
7条回答
  • 2020-12-14 00:52
    1. Right-clicking the .NET Core app in your project

    2. Clicking Set as StartUp Project

    0 讨论(0)
  • 2020-12-14 01:09

    The issue here is this particular line in your .csproj file

    <TargetFramework>netstandard2.0</TargetFramework>

    change it to

    <TargetFramework>netcoreapp2.1</TargetFramework>

    or whatever the version of .net core your main project is targetting, It worked for me, it should work for you too!! :)

    0 讨论(0)
  • 2020-12-14 01:09

    Step1:
    Add ProjectReference your project .netstandar".

    Step2:
    You can use the parameter -Project "your project .netstandar".

    0 讨论(0)
  • 2020-12-14 01:10

    I'm actually trying to do this also. I got the scaffolding but Net Standard doesn't seem to load the extensions for table properties.

    Make sure you install the EntityFrameworkCore.Tools package for EF. You only need 4.6.1 support which is the default. If I figure out how to fix the extensions issue I'll post here.

    These two are required:
    Install-Package Microsoft.EntityFrameworkCore.SqlServer
    Install-Package Microsoft.EntityFrameworkCore.Tools

    0 讨论(0)
  • 2020-12-14 01:10

    The following works from the dotnet CLI assuming you already have a executable startup project in the solution:

    dotnet ef dbcontext scaffold "Server=myServerName; Database=dbName; User Id=someUser; Password=myPassword123;" Microsoft.EntityFrameworkCore.SqlServer  --project ../MyLibraryProject/ -c MyDbContext -o FolderName
    

    you can find more information here:

    https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#other-target-frameworks

    0 讨论(0)
  • You can run dotnet ef migrations against .NET Standard projects by creating a .NET Core project, adding your .NET Standard project as a reference, then using the --project and --startup-project to specify which project to run the migrations against.

    dotnet ef migrations add MyNewMigrationName --project [pathToNetStandardProject] --startup-project [pathToNetCoreProject]

    0 讨论(0)
提交回复
热议问题