Traditional sql approach VS ORM [closed]

醉酒当歌 提交于 2019-12-08 16:11:31
Backs

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.

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 :(

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!