Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Entity Framework and a Database project together?

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.

like image 667
Steven Lemmens Avatar asked Oct 09 '19 07:10

Steven Lemmens


People also ask

What databases work with Entity Framework?

EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.

Does Entity Framework Create database?

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.

How do I add Entity Framework to an existing project?

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.


2 Answers

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.

like image 59
Uberacy Tottoli Jr. Avatar answered Nov 03 '22 00:11

Uberacy Tottoli Jr.


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

like image 41
hamiltonjose Avatar answered Nov 03 '22 01:11

hamiltonjose