Search code examples
databaseasp.net-core-mvcedmx

How to connect asp net core app to .net class library with edmx


I have a mvc application which I do not want to change. I also want to create an asp.net core web application with angular. I also have a ms sql database with and ado.net/edmx project.

Know I want to get my users, stored in the database. How can I reference my database project?

I have tried creating a new EF project with database first but that means changing other applications as well.


Solution

  • This is already a supported scenario. The only condition is that your ASP.NET Core project must target .NET Framework instead of .NET Core. See: https://learn.microsoft.com/en-us/aspnet/core/data/entity-framework-6?view=aspnetcore-2.2. For what it's worth, .NET Core 3.0 will support EF 6 natively, so eventually, you'll be able to target .NET Core again, if you choose this path.

    Short of that, you should be able to create an EF Core library to work with your existing database which your ASP.NET Core project can then utilize. Since it's referencing the same database and not making any direct alterations to the schema, it should have no bearing on any other applications.