SlideShare a Scribd company logo
TUGA IT 2016
LISBON, PORTUGAL
THANK YOU TO OUR
SPONSORS
THANK YOU TO OUR
TEAM
ANDRÉ BATISTA ANDRÉ MELANCIA ANDRÉ VALA ANTÓNIO LOURENÇO BRUNO LOPES CLÁUDIO SILVA
NIKO NEUGEBAUER
RUI REISRICARDO CABRAL
NUNO CANCELO PAULO MATOS PEDRO SIMÕES
SANDRA MORGADO SANDRO PEREIRARUI BASTOS
NUNO ÁRIAS SILVA
ORMs Meet SQL
Ricardo Peres
@rjperes75
About Me
• Technical Evangelist at Simplifydigital (UK)
• Microsoft MVP, Visual Studio and Development Technologies
• Blogger
@rjperes75
rjperes@hotmail.com
http://weblogs.asp.net/ricardoperes
Agenda
• ORMs: The Good Parts
• The Problem
• How ORMs Try to Solve It
• Case Studies
• NHibernate and Entity Framework
• Micro ORMs
• Conclusion
• Food for Thought
ORMs: The Good Parts
ORMs are good at a number of things:
• Abstracting away databases and database-specific mechanisms (e.g., IDENTITY, sequences)
• Shielding us from database changes (e.g., using mappings)
• Ids are properly handled and propagated to children
• Avoiding writing tedious and repeating SQL (e.g., SQL is generated for us)
• Transactions and concurrency management is done for us
• Enforcing usage of good patterns (e.g., using parameters, no *)
• Embracing language-specific idioms and patterns (e.g., LINQ)
• Detecting changes for us (in entities and in model)
• Allow for complex scenarios that are not supported in relational databases (e.g., inheritance)
• Permit focusing on the language that developers are more proficient at (e.g., Java, C#) – enter
Domain Driven Design
• Fast to get things working (e.g., CRUDs, lists, binding)
The Problem (1 of 2)
It is generally accepted that ORMs make our lifes, as developers, easier,
but…
• SQL produced by ORMs is usually far from optimal / fast
This is usually because of the need for generic querying avoiding DB-specific
mechanisms
• Hiding complexity is not always a good thing
ORMs do somewhat complex stuff and make it seem simple
• Not meant to be used for everything
“If all you have is a hammer, everything looks like a nail”
ETL, reporting are two exemples of bad usage
The Problem (2 of 2)
It turns out that:
• SQL is still the most powerful way to perform queries in relational
databases
ORMs generally avoid advanced SQL
• Abstraction loses database-specific features
Lowest common denominator
• Generated schemas still require intervention / maintenance
DBAs are still required to tune the generated schemas, enforce conventions,
generate indexes, etc
How ORMs Try to Solve It (1 of 5)
• Two workflows:
• Database first – ORMs can adapt to what is already there
• Code first – It is possible to influence or bypass ORM functionality
• Some ORM features may come handy:
• Custom SQL
• Schema hints
• Lazy and eager loading
• Batching
• Cache
• Optimistic concurrency
How ORMs Try to Solve It (2 of 5)
Custom SQL
• It is possible to load, save,
update and delete entities from
user-supplied SQL, even stored
procedures
Index creation hints
• Besides primary keys, it is
possible to tell ORMs to
generate indexes for certain
columns
How ORMs Try to Solve It (3 of 5)
Lazy loading and lazy properties
• References (one-to-one, many-
to-one, one-to-many, many-to-
many) are only loaded when and
if necessary
• Even simple properties can be
loaded on demand (e.g., CLOB,
BLOB)
Eager loading
• It is possible to request that
entity references be loaded
together with the main entity
How ORMs Try to Solve It (4 of 5)
Batching queries
• ORMs can send together several
queries at once (both CUDs and
queries)
Batch loading
• When one loads a collection in a
loaded entity, up to N collections
in other loaded entities are
loaded too
How ORMs Try to Solve It (5 of 5)
Cache
• First and second level caches
means that we don’t even have
to go to the database
Optimistic concurrency
• Either a specific column or a set
of columns can be used for
detecting changes transparently
Case Study: NHibernate and Entity
Framework
NHibernate
• Mature and proven
• Lots of features
• Many supported databases
• Steeper learning curve
• No documentation
• Poor community support
Entity Framework
• Good integration with MS prods
• Is getting better on every version
• Good documentation
• Unstable
• Less features
• Only works well with SQL Server
Case Study: NHibernate and Entity
Framework
Feature NHibernate Entity Framework
Index creation hints X X
Lazy loading X X
Eager loading X X
Lazy properties X
Custom SQL X X
Batching CUDs X X
Batching queries X
Batch loading X
Cache X X
Optimistic concurrency X X
Case Study: Micro ORMs
• Micro ORMs do not attempt to be feature-rich
• Simple, sometimes it’s a single code file
• Fast
• No advanced features
• You still have to write your own SQL - no native querying (e.g., LINQ)
• Stuck to conventions for mapping
Conclusion
• ORMs are good to have at hand, but may not always be the best
solution
• Know your requirements
• Explore your ORM and get to know its full potential
• Use the best tool for the job at hand
• Understand what is going on underneath
• DBAs are not your enemies – learn from them!
• Learn SQL
Food for Thought
• Ten advantages of an ORM
• The Vietnam of Computer Science
• When Should I Use An ORM?
• Why debate politics when you can just blog about ORMs?
• What ORMs have taught me: just learn SQL
• Reply to "What ORMs have taught me: just learn SQL“
• ORM is an anti-pattern
• ORM Is an Offensive Anti-Pattern
• ORM Haters Don’t Get It
Q & A
?
Thank You!
Let me hear from you!
THANK YOU TO OUR
SPONSORS

More Related Content

PPTX
Java Programming Important Topics
PDF
Oracle - Introduction
PPTX
Common issues, rules and principles
PPT
Introduction what is java
PPT
RIBBUN SOFTWARE
PDF
How I Learned To Stop Worrying (And Love The KiCad)
PDF
Automating angular
PPTX
Scalable Open Source
Java Programming Important Topics
Oracle - Introduction
Common issues, rules and principles
Introduction what is java
RIBBUN SOFTWARE
How I Learned To Stop Worrying (And Love The KiCad)
Automating angular
Scalable Open Source

What's hot (9)

PPTX
20200115 admin group_networking_party_v2
PDF
Optimizing Laravel for content heavy and high-traffic websites by Man, Apples...
PDF
Object Oriented Programming in Swift Ch0 - Encapsulation
PDF
Introduction to java
PDF
Introduction to Object Oriented Programming & Design Principles
PDF
Introduction to Object Oriented Programming & Design Principles
PDF
OSGi Community Event 2010 - OSGi and Android
PDF
Scala days mizushima
PPTX
How to write test in node.js
20200115 admin group_networking_party_v2
Optimizing Laravel for content heavy and high-traffic websites by Man, Apples...
Object Oriented Programming in Swift Ch0 - Encapsulation
Introduction to java
Introduction to Object Oriented Programming & Design Principles
Introduction to Object Oriented Programming & Design Principles
OSGi Community Event 2010 - OSGi and Android
Scala days mizushima
How to write test in node.js
Ad

Viewers also liked (15)

PPS
Pecha Kucha Rene
PPT
Presentation On Edf 2005
PPTX
Presentación1
PPTX
Web app first scan
PDF
Sma tee adapter female female female
PDF
PDF
Sma female to reverse polarity sma male adapter
PPTX
Elasticsearch
PDF
GLIIFCA 22 final (1)
PDF
Bomba Jacuzzi Série F-G
DOC
Enrique rojas-el-hombre-light
PPTX
Building Enterprise Search Engines using Open Source Technologies
PPTX
KOOS-BMECTE
PDF
A Retrospective Study to Investigate Association among Age, BMI and BMD in th...
Pecha Kucha Rene
Presentation On Edf 2005
Presentación1
Web app first scan
Sma tee adapter female female female
Sma female to reverse polarity sma male adapter
Elasticsearch
GLIIFCA 22 final (1)
Bomba Jacuzzi Série F-G
Enrique rojas-el-hombre-light
Building Enterprise Search Engines using Open Source Technologies
KOOS-BMECTE
A Retrospective Study to Investigate Association among Age, BMI and BMD in th...
Ad

Similar to ORMs Meet SQL (20)

PPTX
The tortoise and the ORM
PPTX
Scaling a High Traffic Web Application: Our Journey from Java to PHP
PPTX
Scaling High Traffic Web Applications
PPTX
Why databases cry at night
PPT
The economies of scaling software - Abdel Remani
PPT
The Economies of Scaling Software
PPTX
Babysitting your orm essenmacher, adam
PDF
Breaking data
PPTX
ORM Methodology
PPTX
Clean code
PDF
ITB2017 - Slaying the ORM dragons with cborm
PPTX
Hard Coding as a design approach
PPS
MySQL Optimization from a Developer's point of view
PDF
Big Data! Great! Now What? #SymfonyCon 2014
PDF
Introduction to Machine Learning for Oracle Database Professionals
PDF
20140228 fp and_performance
PPTX
Fontys Lecture - The Evolution of the Oracle Database 2016
PPTX
1. SQL Server forSharePoint geeksA gentle introductionThomas Vochten • Septem...
PDF
Dev buchan 30 proven tips
PDF
Ideas spracklen-final
The tortoise and the ORM
Scaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling High Traffic Web Applications
Why databases cry at night
The economies of scaling software - Abdel Remani
The Economies of Scaling Software
Babysitting your orm essenmacher, adam
Breaking data
ORM Methodology
Clean code
ITB2017 - Slaying the ORM dragons with cborm
Hard Coding as a design approach
MySQL Optimization from a Developer's point of view
Big Data! Great! Now What? #SymfonyCon 2014
Introduction to Machine Learning for Oracle Database Professionals
20140228 fp and_performance
Fontys Lecture - The Evolution of the Oracle Database 2016
1. SQL Server forSharePoint geeksA gentle introductionThomas Vochten • Septem...
Dev buchan 30 proven tips
Ideas spracklen-final

More from Ricardo Peres (12)

PPTX
MongoDB com EF Core - Porto.DATA #96 28/08/2024
PPTX
EF Core 7
PPTX
Elasticsearch
PPTX
Microsoft Embracing Open Source Technologies
PPTX
Elasticsearch
PPTX
Entity Framework 7: What's New?
PPTX
Entity Framework 7
PPTX
Microsoft ♥ Open Source
PDF
Software Developer's Journal - 02/2012
PPTX
TechDays 2010 - Introdução ao NHibernate
PPTX
SharePoint 2010 Business Connectivity Services - Introdução
PPTX
MVP Showcase 2015 - Entity Framework 7 - NoORM
MongoDB com EF Core - Porto.DATA #96 28/08/2024
EF Core 7
Elasticsearch
Microsoft Embracing Open Source Technologies
Elasticsearch
Entity Framework 7: What's New?
Entity Framework 7
Microsoft ♥ Open Source
Software Developer's Journal - 02/2012
TechDays 2010 - Introdução ao NHibernate
SharePoint 2010 Business Connectivity Services - Introdução
MVP Showcase 2015 - Entity Framework 7 - NoORM

Recently uploaded (20)

PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
history of c programming in notes for students .pptx
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
history of c programming in notes for students .pptx
CHAPTER 2 - PM Management and IT Context
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Monitoring Stack: Grafana, Loki & Promtail
iTop VPN Crack Latest Version Full Key 2025
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Advanced SystemCare Ultimate Crack + Portable (2025)
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Oracle Fusion HCM Cloud Demo for Beginners
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Weekly report ppt - harsh dattuprasad patel.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
iTop VPN Free 5.6.0.5262 Crack latest version 2025
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Navsoft: AI-Powered Business Solutions & Custom Software Development

ORMs Meet SQL

  • 2. THANK YOU TO OUR SPONSORS
  • 3. THANK YOU TO OUR TEAM ANDRÉ BATISTA ANDRÉ MELANCIA ANDRÉ VALA ANTÓNIO LOURENÇO BRUNO LOPES CLÁUDIO SILVA NIKO NEUGEBAUER RUI REISRICARDO CABRAL NUNO CANCELO PAULO MATOS PEDRO SIMÕES SANDRA MORGADO SANDRO PEREIRARUI BASTOS NUNO ÁRIAS SILVA
  • 4. ORMs Meet SQL Ricardo Peres @rjperes75
  • 5. About Me • Technical Evangelist at Simplifydigital (UK) • Microsoft MVP, Visual Studio and Development Technologies • Blogger @rjperes75 rjperes@hotmail.com http://weblogs.asp.net/ricardoperes
  • 6. Agenda • ORMs: The Good Parts • The Problem • How ORMs Try to Solve It • Case Studies • NHibernate and Entity Framework • Micro ORMs • Conclusion • Food for Thought
  • 7. ORMs: The Good Parts ORMs are good at a number of things: • Abstracting away databases and database-specific mechanisms (e.g., IDENTITY, sequences) • Shielding us from database changes (e.g., using mappings) • Ids are properly handled and propagated to children • Avoiding writing tedious and repeating SQL (e.g., SQL is generated for us) • Transactions and concurrency management is done for us • Enforcing usage of good patterns (e.g., using parameters, no *) • Embracing language-specific idioms and patterns (e.g., LINQ) • Detecting changes for us (in entities and in model) • Allow for complex scenarios that are not supported in relational databases (e.g., inheritance) • Permit focusing on the language that developers are more proficient at (e.g., Java, C#) – enter Domain Driven Design • Fast to get things working (e.g., CRUDs, lists, binding)
  • 8. The Problem (1 of 2) It is generally accepted that ORMs make our lifes, as developers, easier, but… • SQL produced by ORMs is usually far from optimal / fast This is usually because of the need for generic querying avoiding DB-specific mechanisms • Hiding complexity is not always a good thing ORMs do somewhat complex stuff and make it seem simple • Not meant to be used for everything “If all you have is a hammer, everything looks like a nail” ETL, reporting are two exemples of bad usage
  • 9. The Problem (2 of 2) It turns out that: • SQL is still the most powerful way to perform queries in relational databases ORMs generally avoid advanced SQL • Abstraction loses database-specific features Lowest common denominator • Generated schemas still require intervention / maintenance DBAs are still required to tune the generated schemas, enforce conventions, generate indexes, etc
  • 10. How ORMs Try to Solve It (1 of 5) • Two workflows: • Database first – ORMs can adapt to what is already there • Code first – It is possible to influence or bypass ORM functionality • Some ORM features may come handy: • Custom SQL • Schema hints • Lazy and eager loading • Batching • Cache • Optimistic concurrency
  • 11. How ORMs Try to Solve It (2 of 5) Custom SQL • It is possible to load, save, update and delete entities from user-supplied SQL, even stored procedures Index creation hints • Besides primary keys, it is possible to tell ORMs to generate indexes for certain columns
  • 12. How ORMs Try to Solve It (3 of 5) Lazy loading and lazy properties • References (one-to-one, many- to-one, one-to-many, many-to- many) are only loaded when and if necessary • Even simple properties can be loaded on demand (e.g., CLOB, BLOB) Eager loading • It is possible to request that entity references be loaded together with the main entity
  • 13. How ORMs Try to Solve It (4 of 5) Batching queries • ORMs can send together several queries at once (both CUDs and queries) Batch loading • When one loads a collection in a loaded entity, up to N collections in other loaded entities are loaded too
  • 14. How ORMs Try to Solve It (5 of 5) Cache • First and second level caches means that we don’t even have to go to the database Optimistic concurrency • Either a specific column or a set of columns can be used for detecting changes transparently
  • 15. Case Study: NHibernate and Entity Framework NHibernate • Mature and proven • Lots of features • Many supported databases • Steeper learning curve • No documentation • Poor community support Entity Framework • Good integration with MS prods • Is getting better on every version • Good documentation • Unstable • Less features • Only works well with SQL Server
  • 16. Case Study: NHibernate and Entity Framework Feature NHibernate Entity Framework Index creation hints X X Lazy loading X X Eager loading X X Lazy properties X Custom SQL X X Batching CUDs X X Batching queries X Batch loading X Cache X X Optimistic concurrency X X
  • 17. Case Study: Micro ORMs • Micro ORMs do not attempt to be feature-rich • Simple, sometimes it’s a single code file • Fast • No advanced features • You still have to write your own SQL - no native querying (e.g., LINQ) • Stuck to conventions for mapping
  • 18. Conclusion • ORMs are good to have at hand, but may not always be the best solution • Know your requirements • Explore your ORM and get to know its full potential • Use the best tool for the job at hand • Understand what is going on underneath • DBAs are not your enemies – learn from them! • Learn SQL
  • 19. Food for Thought • Ten advantages of an ORM • The Vietnam of Computer Science • When Should I Use An ORM? • Why debate politics when you can just blog about ORMs? • What ORMs have taught me: just learn SQL • Reply to "What ORMs have taught me: just learn SQL“ • ORM is an anti-pattern • ORM Is an Offensive Anti-Pattern • ORM Haters Don’t Get It
  • 21. Thank You! Let me hear from you!
  • 22. THANK YOU TO OUR SPONSORS