Home > database >  Whether it is appropriate to use Entity Framework versus ADO.NET for multi table joins?
Whether it is appropriate to use Entity Framework versus ADO.NET for multi table joins?

Time:01-04

I'm writing a Web API with a couple of endpoints. Each endpoint queries the database and it involves a join between 2 to 6 tables.

I have previously used Entity Framework, but only for single tables. So I want to ask whether it is appropriate to use Entity Framework for multiple table joins, or should I stick with ADO.NET based SQL queries?

CodePudding user response:

Yes. EF enables you to express the query logic using LINQ queries over your entities, and will translate to SQL. It's a core function of EF, and it's very common to see it used in a Web API to fetch Entities from the database, and then serialize the Entities as JSON for sending to the client.

Using EF's built-in database-to-Entity mapping and .NET's built-in Entity-to-JSON mapping makes writing a Web API very simple.

Of course you should monitor the SQL generated by EF, and there are scenarios where you might drop down to Raw SQL Queries, Dapper, or ADO.NET. But for the basic use case of building a simple Web API, EF Core ASP.NET Core is the simplest answer.

See eg Tutorial: Create a web API with ASP.NET Core

  • Related