At a conference yesterday, I learned about the importance of putting your database in source control. They showed us how to make a new Database project and import the database.
What I was wondering about is how I would change an existing project running on Entity Framework to utilize the database project's power? Schema updates have always been done by using Entity Framework Migrations. I get that the Database project will be able to deploy database updates for me and save those update scripts to source control, but I would like to keep Entity Framework for querying my data (if that makes any sense at all).
Is it possible (or even: recommended) to use Entity Framework to access the database but manage the database using a Database project in Visual Studio ? How do you go about this?
I've tried searching for similar questions and using Google to find if anyone else is having the same problem, but no dice so far.
I should also state that I am considering using this in databases that also have stored procedures in them. These are not controlled through Entity Framework at all, and therefore are not in source control yet.
Thank you for your time.
EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.
Sometimes creating a database for your applications can be a tedious task. However, with ASP.NET you can use Entity Framework to generate a database based on an object model.
Install Entity Framework to your Project. Right click on your project name and select Manage NuGet Packages. Go to Browse and Select Entity Framework then click Install button to install Entity Framework on your project.
What I was wondering about is how I would change an existing project running on Entity Framework to utilize the database project's power?
Answer: I suggest you to see this course from Plural Sight : https://www.pluralsight.com/courses/code-first-entity-framework-legacy-databases
Is it possible (or even: recommended) to use Entity Framework to access the database but manage the database using a Database project in Visual Studio ? How do you go about this?
Answer: Yes, it's possible and recommended. Your data project becomes the source of truth about the structure of your database. This is very powerful to keep control of all the changes and state of your database in one place (Visual Studio). The course from the first answer will teach you how.
I should also state that I am considering using this in databases that also have stored procedures in them. These are not controlled through Entity Framework at all, and therefore are not in source control yet.
Answer: I don't see any problem using stored procedures. The tool from the Plural Sight course will create the procedure in your source control and the reverse engineering will create a class/method for easy use of the proc.
I just came across the below alternative, which I didn't test though:
Generate Entity Framework Core classes from a SQL Server database project - .dacpac file
I believe this should be something to be considered
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With