Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I migrate to Entity Framework? [closed]

I've been using the SqlCommand class and writing my own T-SQL queries for a very long time. I've stuck with it because I'm comfortable with it, and it probably stemmed from me starting as a windows developer in the days before we had many other great options. I've been doing web development now for about 10 years, and still using it and writing my own query strings. I've written a dynamic class for all my database needs on the fly, all I have to do is write the T-SQL, which I can do quickly and use in any project.

Other developers have got big eyed when they see my code, and encourage me to learn LINQ which I do not like at all.

I'm starting a new project now in ASP.NET MVC and now feel like I should get out of the dinosaur days and move to Entity Framework to handle my data.

I know that the SqlCommand class is the nuts and bolts of the Entity Framework behind the scenes, so I feel like why should I go through the middle man (entity) to achieve the same results and spend time learning something new.

Can someone please explain to me why I need to move on, or if I should stick with what I know?

like image 251
prospector Avatar asked Jul 16 '14 05:07

prospector


People also ask

Can I use EF core without migration?

If you'd like to access data from an existing database and tables with Entity Framework (EF) Core in your ASP.NET Core Web API project, you can try to use Scaffold-DbContext command or dotnet ef dbcontext scaffold command to generate code for a DbContext and entity types for your database.

What is use of migration in Entity Framework?

The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

When should I choose Entity Framework?

The Entity Framework enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern themselves with the underlying database tables and columns where this data is stored.

Is Entity Framework worth using?

Conclusion. EF should be considered a great ORM framework which allows faster development, easier and quicker operations to the DB, as long as you are careful and know how it works in order to avoid certain mistakes and create performance problems.


2 Answers

Well, with SqlCommand... If you're doing it right, you've either already written the equivalent of an ORM, or you are spending a lot of time writing code that does stuff like packaging up arguments, and mapping columns to objects. If you're not doing either of those, then chances are you have unsafe code and are passing around untyped DataSets and then doing lots of casting, or you're doing dangerous concatenated SQL queries that are prone to SQL Injection.

The advantage of of using EF (or any ORM) is that it handles the SQL generation, the object mapping, the parameter packaging, and gives you a very powerful query interface that lets you write multiple queries very quickly.

Why write 10 lines of code when you can write one?

Whether or not you use EF is really a personal choice... but if you're doing serious, object oriented development, you should be using an ORM of some kind (maybe even a micro ORM, like dapper or massive). Or write your own micro-orm for that matter.

It's just a huge pain to use ADO without some kind of automatic mapping technology.

like image 139
Erik Funkenbusch Avatar answered Oct 02 '22 16:10

Erik Funkenbusch


The main reasons to switch to EF is

  • It is faster to develop with EF once you learnt it
  • Especially joins are simpler to write in most cases
  • You get compile time checking that all your columns and tables actually exists
  • You have the option to use EF migrations that is one of the best database migration tools out there

I switched years ago (via Linq2SQL) and have never looked back.

Go for EF code first and use migrations.

like image 45
Albin Sunnanbo Avatar answered Oct 02 '22 16:10

Albin Sunnanbo