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.<
Right-clicking the .NET Core app in your project
Clicking Set as StartUp Project
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!! :)
Step1:
Add ProjectReference your project .netstandar".
Step2:
You can use the parameter -Project "your project .netstandar".
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
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
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]