I'm trying to migrate an old API to Azure Functions. This API uses an edmx to define and connect to an Azure SQL database.
I need to recreate the code and the connection for this database in a new solution with the following conditions:
- My newly generated edmx should match the existing database/existing code
- When I deploy, it should NOT recreate the tables, but connect to the existing tables and interact with existing data
- It needs to work with Azure Functions
- I'm developing in Visual Studio Code
So far, I haven't been able to find a guide that explains how to do this. I've found a few articles on how to create an edmx from scratch, but failing conditions 2 and 4 (and not sure about 3). I'm having difficulty finding a starting point.
Is this possible, or do I need to change my approach?
Porting or creating a .edmx into VS Code just isn't possible - it is no longer supported in EntityFrameworksCore. Fortunately, it isn't necessary.
First and foremost, I needed a connection to the existing database - the answer was to Reverse Engineer the Scaffolding using 'Scaffold-Dbcontext,' which generated the models and the context. I needed to grab the connection string to this database from Azure for the script, but after running it I replaced the connection string with a reference to my local.settings.json so I won't be checking it into source control (See reference document, it leaves a warning in code where it does this). From there, I was able to reuse much of the original code, swapping out the new DbContext, and enabling it via dependency injection in my Startup.cs