Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is EF Core Add Migration Supported from .NET Standard Library?

We have been trying to run EF Core Migration in .Net Standard 1.6 class library, but it has been failing. But same passes very well in .Net Core 1.1 class library.

Is EF Migration supported in .NET STANDARD?

like image 478
Abhijeet Avatar asked Jun 08 '17 08:06

Abhijeet


People also ask

How do I add migration to EF core?

Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.

Does EF core support automatic migration?

EF core doesn't support automatic migrations . So you have to do it manually.

Does Entity Framework support .NET standard?

EF 6 supports . NET Standard 2.1, which is currently supported by . NET Core 3.0 or later - no . NET Framework version.


1 Answers

The documentation covers this case as know issue/limitation when the DbContext is placed inside an netstandardx.y Class Library.

Workaround 1 - Use an app as the startup project

If you have an existing .NET Core App or .NET Framework App (including an ASP.NET Core Web Application), you can use it as the startup project. If not, you can create a new one just for use with the .NET Command Line Tools. Specify a startup project that is a "runnable app." Example: console

dotnet ef migrations list --startup-project ../MyConsoleApp/ 

Workaround 2 - Cross-target a runnable framework

Add an additional target framework to the class library project. This can a version of either .NET Core App or .NET Framework. To make the project a .NET Core App, add the "netcoreapp1.0" framework to project like in the sample below: XML

<Project Sdk="Microsoft.NET.Sdk">   <PropertyGroup>     <TargetFrameworks>netcoreapp1.0;netstandard1.4</TargetFrameworks>   </PropertyGroup> </Project> 

When targeting .NET Framework, ensure you project targets version 4.5.1 or newer. XML

<Project Sdk="Microsoft.NET.Sdk">   <PropertyGroup>     <TargetFrameworks>net46;netstandard1.4</TargetFrameworks>   </PropertyGroup> </Project> 
like image 96
Tseng Avatar answered Sep 21 '22 09:09

Tseng