1

I'm trying to create an UWP application with an opportunity to launch many quiz based games. For this reason I have a Core project(UWP) which will display all the gamemodes. Each gamemode is implemented in its own project, and I'd like to add a separate Data Access Layer to every gamemode. (The DAL would implement the Repository pattern)

So, my Core project (UWP) references the AllOrNothing(Class Library Universal Windows) project. Until this point it's fine. When I'm trying to add a project which will used by the Entity Framework I don't really know which type of project should I choose.

  • If I see it correctly only .NET Standard 2.0 and the specific UWP class libraries can be referenced from the AllOrNothing(UWP Library) project. For example if I try to reference a .NET 6 project from the UWP library it throws an error.

So I added a .NET Standard 2.0 Library, and installed the EF(version 6.4.4), and EF Core(version 3.1.22) When I run the command add-migration Init, it says the following: Project 'QuizProgram.Core' targets framework '.NETStandard'. The Entity Framework Package Manager Console Tools don't support this framework. (QuizProgram.Core is my startup project) I don't really understand the problem, and can't really solve it.

I'm using Visual Studio 2022.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
ombolics
  • 27
  • 6
  • It seems that [EF6 supports .NET Standard 2.1](https://stackoverflow.com/questions/58381122/can-entity-framework-6-be-used-in-a-net-standard-project). And you might need to use EF core 5.0 as well because [EF core 5.0 supports .NET Standard 2.1](https://learn.microsoft.com/en-us/ef/core/miscellaneous/platforms#universal-windows-platform). – Roy Li - MSFT Dec 21 '21 at 01:37
  • I can't use .NET Standard 2.1, because it can't be referenced from UWP – ombolics Dec 21 '21 at 10:39
  • Then I think you might need to use EF with a lower version which supports .NET Standard 2.0 – Roy Li - MSFT Dec 22 '21 at 03:23

1 Answers1

0

You cannot reference .NET Core/5/6 or Standard 2.1 projects from UWP, as you have found out yourself. You can reference .NET Framework 4.8 or earlier (if your UWP project is the same version or later as the target) or .NET Standard 2.0.

If you might want to share the library with .NET Core/5/6 then you need to select .NET Standard 2.0. If you don't, then .NET 4.8 is a better choice as it is a newer version of the framework.

It sounds like you are using .NET Standard 2.0. In this case you will need to use DF 3.1.22 or earlier for compatibility purposes. You will also need to use a startup project that references either .NET framework or .NET Core and also the .NET Standard library where you have your EF model defined, because .NET Standard 2.0 cannot perform the migrations. The syntax for this is as follows:

dotnet ef migrations script --project YourNetStandardEFModel --startup-project YourNet48ProjectReferencingIt
Peter Dongan
  • 1,762
  • 12
  • 17
  • I created a project with .NET Framework 4.8 (EFHelper), referenced the EFModel project from it, and after running the command you suggested, I got the following issue: – ombolics Dec 20 '21 at 22:24
  • Path\QuizProgram_V01\EFHelper\obj\EFHelper.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "GetEFProjectMetadata". [C:\Users\Csabi\Documents\Személyes\Ta4,5): error MSB4006: There is a circul4,5): er4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "GetEFProjectMetadata". Path\QuizProgram_V01\EFHelper\EFHelper.csproj] Unable to retrieve project metadata. Ensure it's an SDK-style project. – ombolics Dec 20 '21 at 22:24
  • If you're using a custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option. – ombolics Dec 20 '21 at 22:24
  • I've run this PMC console as well: Add-Migration Initial -Project QuizGame.AllOrNothing.Repository -StartupProject EFHelper but this gave me another error: – ombolics Dec 20 '21 at 22:25
  • The interesting part of it, that the error message lies, because the EFHelper is not .NET Standard but .NET Framework 4.8, it's 100% – ombolics Dec 20 '21 at 22:26