1

I'm doing a project with ASP.net core. I found that most of developers use Entity Framework for dealing with the database. I have worked with raw SQL queries with ASP.NET. I'm using SQL SERVER 2014 and have to develop a RESTfull API to deal with my database. My database consists of about 50 tables.

So my question is, what method is better for my task, using Entity Framework or using raw SQL queries?

From my research I have found that Entity Framework has basically two methods, Code first and Database first. I have looked into both methods. I need to know pros and cons of using entity framework compared to normal SQL queries. And finally is there a effect on .net core with entity framework?

MLPJ
  • 108
  • 1
  • 12
  • Possible duplicate of [Code-first vs Model/Database-first](https://stackoverflow.com/questions/5446316/code-first-vs-model-database-first) – Igor Oct 05 '17 at 18:36
  • 1
    actually i'm asking about entity framework vs SQL queries @Igor – MLPJ Oct 05 '17 at 18:51
  • 1
    I was torn between voting this as too broad, too opinionated, or mark it as a dupe. You did mention Code First and DB First so I went with dupe as there will not be a good answer for your original question *and* the duplicate has some good information so at least you get something out of it. – Igor Oct 05 '17 at 18:53
  • i read that one. thanks anyway – MLPJ Oct 05 '17 at 18:56
  • 1
    https://blogs.msdn.microsoft.com/gblock/2006/10/26/ten-advantages-of-an-orm-object-relational-mapper/ – Steve Greene Oct 05 '17 at 19:02

3 Answers3

2

It seems that you have a large application, my recommendation is that you should use Entity Framework because you have LINQ. (Examples here: http://www.entityframeworktutorial.net/Querying-with-EDM.aspx).

With LINQ you can build your queries using methods instead of strings.

With LINQ:

var L2EQuery = context.Students.where(s => s.StudentName == "Bill");

With Native SQL:

var studentName = ctx.Students
                     .SqlQuery("Select studentid, studentname, standardId 
                                from Student 
                                where studentname='Bill'")
                     .FirstOrDefault<Student>();
Kenji Mukai
  • 599
  • 4
  • 8
1

Using entity framework with code first migrations and a decoupled from ef repository pattern architecture does not restrict you from using sql queries as well sometimes when you need to.

Yuri Zolotarev
  • 721
  • 9
  • 23
0

Your question will be closed because it is too opinion oriented.

But yes, personally, I greatly encourage the use of Entity Framework.

The thing is, if you have no experience at all in EF, then you will be subject to a learning curve. Which means it will still be easier for you to simply use SQL query in your code. That said, if you take your time and learn correctly how to use EF it will probably be of good use later.

I've experienced both Entity Framework and raw SQL queries, and now that i'm used to EF, I find it much better.

Antoine Pelletier
  • 3,164
  • 3
  • 40
  • 62