I have a database context defined in a .NET Standard 2.0 project so that it can be consumed by both .NET 5.0 and .NET 4.7.x clients. I am trying to create an initial migration and generate scripts from it. I am using the following command to generate the migration:
dotnet ef migrations add InitialCreate --project My.Standard.DataContext.Project --startup-project My.DotNet5.Api
In order for the Standard project to build I need to create the migration using Entity Framework version 3.1.21 as more recent versions don't work with .NET Standard 2.0. However when I run the above command, the packages in the .NET 5.0 API automatically update to 5.0.12, meaning the migration code that is generated is incompatible with the Standard project that includes it.
Why is this happening? How do I stop it happening?
My best guess is that it is because I am using something that is not compatible with 3.1.21. I know that I currently am using strings for the Ids and iirc that is not possible out of the box in 3.1.21.
Here is the project file before it changes automatically:
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.21" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.21" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.21">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Identity.Web" Version="1.20.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
CodePudding user response:
This is working as expected now after I did two things. (One or the other might be unrelated.)
- I changed the string Id to an int, in order to be compatible with EF 3.1.21
- I cleaned the solution.