0
votes

is it possible to have a common code base for model / context / migrations to use the same SQL DB from asp.net core app (3.1) and .net framework app (4.6.1)? My attempts failed. Is there no other solution than creating two projects, one with EF core in .net core 3.1 assembly and one with EF6 with target 4.6.1.

I tried to create a .net standard 2.0 project (with only EF core) that I can reference from both apps, but that seems not to possible? Failed to use the migration tools, because .net standard 2.0 only an "interface"?

dotnet ef migrations add InitialCreate

> Startup project 'TestStandard.csproj' targets framework
> '.NETStandard'. There is no runtime associated with this framework,
> and projects targeting it cannot be executed directly. To use the
> Entity Framework Core .NET Command-line Tools with this project, add
> an executable project targeting .NET Core or .NET Framework that
> references this project
1
What exact problem/error you see while using migration tools? I have working projects with data classes in one project (netstandard2.1 library) and app in other (netcoreapp3.1) - Dmitry
Make a 3rd code base for the database that is purely for transactions. Have it emit DataModels via an api. Set up against the API in your other 2 apps. - Zze
@Zze this means on changes in data model I have to change 3 projects? It is the opposite of my aim. - Mustafa
Actual effort difference would be minimal as you can put the data models in a shared csproj across the other 2 solutions. That way changes to the data model in EF automatically go across into the expected api results. - Zze

1 Answers

0
votes

I guess you won't be able to use EF Core (even through NetStandard) and Net 4.6.1 because of compatibility. You could upgrade Net 4.6.1 at least to 4.7.2 and use EF6 or EF Core.

re: Use the migration tool and net standard 2.0 No, you can not. The solution is to create a NetCore project and use it for running migrations (until you migrate all you projects to net core)