1

I am really frustrated of searching this answer that what is better - Traditional System.Data.SqlClient approach or using any ORM like EF or Dapper I have seen many comparisons through many links, some are :

  1. https://github.com/StackExchange/dapper-dot-net enter image description here

  2. http://www.dontpaniclabs.com/blog/post/2014/05/01/speed-comparison-dapper-vs-entity-framework/

  3. ORM vs traditional database query, which are their fields?

One thing that I can understand that, hand written traditional sql code is better in performance than any other approach. but it is still hitting in my mind that if we already had the best approach then why ORMs?

Is it only because we want to reduce DataLayer code? or we dont want to manage our database and want to write everything there in our c# code (code/data first)

Why EF was introduced, if only code management was the problem then, Why and how we are compromising with the performance and speed of query execution, even ORMs has limits.

Please answer my question and let me know if any edit is required.

My only concern is Speed and performance of my website.

Thanks in advance.

4
  • 1
    Your question is asking for opinions and recommendations, both of which Stack Overflow doesn't allow. Aug 11, 2015 at 11:10
  • Please suggest, should I move my question to StachExchange? Aug 11, 2015 at 11:11
  • Programmers StackExchange would be better. Aug 11, 2015 at 11:22
  • 1
    "My only concern is Speed and performance of my website." If this is really true, then why don't you write it in assembler? Probably not, because that would be too difficult, compared to a higher level language. That is an extreme example, but there is a similar trade-off with ORMs: a higher level of abstraction for a (potential) performance hit.
    – Polyfun
    Aug 11, 2015 at 11:23

2 Answers 2

12

I'll try to answer all your questions based on my experience:

  1. Why ORM? ORMs are very good in Model-First approach. When you have your model (your classes, objects, entities, ...) and decided to save it to some storage (DB for example). And here you take suitable ORM and tell it "ok, this class goes to this table" and so on. And this way reduce your DEVELOPMENT time. Of course, you have some overhead on mapping. But, in my experience I had no performance problems with mapping. I had performance problems in all other parts (DB queries, UI render, WCF, ...) but not ORM mapping. So, ORM reduce your development time, insignificantly degrading performance.

  2. ORMs reduce duplicating, reduce complexity and highly increase development time!

  3. Writing everything in C#? Partly - yes. ORM offers strong mapping, so it's nearly impossible to make stupid mistakes like comparing int and string, setting null to not-nullable properties and so on. So, ORM with LINQ-provider offers protection of your code.

  4. Your concerns about performance are exaggerated. Of course, EF (or other ORM) is slower than hand-written SQL code. I believe that in 99% of cases EF will satisfy you and it's much easier to maintain this code, it's self-protected and self-explained.

So, don't look at numbers. They don't have anything common with real life. If you need some additional, I'll try explain.

3
  • after reading your comments, i would like to say thanks you and you well explained my concern as well, you really can be a lecturer in Uni. :) Nov 3, 2016 at 1:01
  • @KevinSimple glad to help :) sometimes i do some lectures on my work :) or write posts: blog.rogatnev.net
    – Backs
    Nov 3, 2016 at 9:48
  • My upvote! But didn't we just dumped webforms over MVC (core now) for the same reason? Webform was also strongly binded, less control but RAD. Mar 13, 2017 at 13:59
6

I would like to add that the Comparison Chart of Dapper is a bit misleading, Entity Framework have one contra - a long startup time (631ms in the Chart). But that's just the first query against the database where models and so one are build in memory.

One thing a ORM can do for you is writing perfectly highly optimized SQL Queries, while at your end you dont have to worry about SQL Syntax and how to map your POCO's to your database tables. Use the ORM Objects like any other IEnumeration.

PS: Would prefer this as comment but < 50 Rep :(

1
  • I'll give you some rep xxx
    – Jasper
    Aug 14, 2015 at 12:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.