Using Entity Framework Core 5 (ef-core-5.0) in a Native c++ application

Viewed 356

Should it be possible to use ef-core-5.0 in a native c++ application using an c++/cli interop assembly with .net core 5 as the target framework? To experiment with this I've modified the netcore branch of the CppCliMigrationSample (https://github.com/mjrousos/CppCliMigrationSample), changing the from "netcoreapp3.1" to "net5.0" for CppCliInterop and the from "net47;netcoreapp3.1" to "net5.0-windows" for the ManagedLibrary. The sample builds and works as expected with these changes. However, adding the efcore 5 assemblies to ManagedLibrary and trying to a simple query on a scaffolded model fails with the following error:- System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=5.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'. I figure I need an entry in the app's .config but I'm not sure what it should be. Can anyone help with resolving this?

Following is what I have in my modified ManagedLibrary.csproj:-

ManagedLibrary.csproj

Sample query:

using ManagedLibrary.Context;
using ManagedLibrary.Model;
using System.Linq;

namespace ManagedLibrary
{
   public static class Mi2cdbData
   {
      public static Prjdata GetFirstProject()
      {
         using (var context = new BaseContext())
         {
            return context.Prjdata.FirstOrDefault();
         }
      }
   }
}

The following shows how it's being called in CppClinterop.cpp:-

CppClinterop.cpp

0 Answers
Related