SlideShare a Scribd company logo
The micro-ORM that will
change your life
Davide Mauri, Director of Software Engineering,
Sensoria
Dapper .NET
Please silence
cell phones
Please silence
cell phones
2
Free online webinar
events
Free 1-day local
training events
Local user groups
around the world
Online special
interest user groups
Business analytics
training
Free Online Resources
PASS Blog
White Papers
Session Recordings
Newsletter www.pass.org
Explore everything PASS has to offer
PASS Connector
BA Insights
Get involved
Davide Mauri
Director of Software
Engineering, Sensoria
A DEVELOPER
20 years in development, started with C++,
then VB & Delphi, then C# and now also
Python. Active on GitHub
A DATABASE GUY
15 years spent on High-Performance
Database, Data Warehouse, Business
Intelligence and Business Analytics projects.
Data Platform MVP since 2007
AGILE & AUTOMATION FAN
Fan of Agile Methodology and Automation, I
try to apply them everywhere he can, to
make sure that "people think, machines do".
IoT is where I live and work now, making
sure the above two worlds work well
together
/davidemauri @mauridb
http://www.sensoriafitness.com/
Agenda
• The story so far: DEV, DBA, ORM, MicroORM
• Dapper.NET
• Basic Usage
• Advanced Stuff
• Extensions
• Conclusions
Let’s start with a definition
fric·tion
The resistance that data finds when it moves from the application to the
database or vice-versa
The resistance that one surface or object encounters when moving over
another.
Friction is bad
- It will slow your performance down
- It will make your DBA scream
- It will make your DEV scream
- It will increase solution costs
© http://becauseracecar.net
Impedance Mismatch
Friction exists because of the “Impedance Mismatch”
• Object Oriented Models and Relational Models are different
• Yet they have to co-exists since they are both really good at their job
Friction also gets generated between teams (DBA vs DEV)
• Code First or Database First?
• Stored Procedure or SQL generated on the fly?
What’s your current status?
Beginner Advanced
I really encourage you to share this presentation with your developers.
The story so far…
DEV usually don’t like to write (and in general deal with) databases, and
SQL code especially
• It looks old…wait: it IS old!
• It’s not OO
• It’s complex/strange/illogic
• It’s really not part of my job
So let’s have something to write the SQL code for us so we can just abstract
from it
• It will even make application work with any DB! That’s a strong selling
point to give to my boss!
The story so far…
ORM (Object-Relational-Mapping) to the rescue
• DEVs don’t write the code
• DBAs still can’t put their hands in code but now is the ORM to blame
Everyone is happy from a relationship perspective
The story so far…
Performance still crappy. Really crappy. Let’s move to a NoSQL db then.
• It was cool in that presentation right?
• No more normalization stuff….Ehy is the word “Normalization” that one
I’m seeing in MongoDB docs?
• Nice: no joins! Well uhm…but now we have *a lot* of duplication in our
data.
• But the fact that I can just put and get my class is soooooo cool and
comfortable.
• The DBA will figure out later how the extract data from it and if the data has some logical
meaning or not. Even in which property the data is stored. Damn! Someone created the
InvoiceValue property but we already had the InvoceAmout to be used. Oh well, let’s add an if,
no, better!, let’s create a solution that via IoC that allows us to configure where I have to look
for Invoice amount. Great let’s do that for all the other fields too!
The story so far…
ORM like EF or NHibernate wrote the SQL code on the fly
• No why to change it if at some point you discover it could have been
written so much better
It would be nice if one could just behave like if the SQL code doesn’t exists:
the DBA will write the code for me and I just map it to my OO objects
• Which is boring anyway.
• There is a tool that, given a query in can automatically map the result
into an OO object of mine?
The story so far…
Devs recently come to realize that – an average - they need to use a DB to
excel in their job
• DB is quite cool again. Lock-Free tables, columnar storage, cool uh?
Still writing interacting with the db is boring (which means error prone)
• Create the connection
• Execute the query
• Map the query to OO objects
• Close the connection
• Oh wait, yeah, exception management
The story so far…
DBA they want to be able to Improve, Fix, Cleanup, Tweak SQL code
written by DEVs.
• Because if the db is slow it’s THEIR problem, even if they DIDN’T wrote
that code.
• But actually they don’t really want to touch DEVs code….is so dirty! And
it’s barely comprehensible. And look how he wrote this statement, oh my
gosh, this prevents index to be used, geez! Look: my poor server is just
out of CPU and I/O!
• Phone calls. It’s the customer care complaining that they cannot do their job,
everything is slow
What a MicroORM is?
Just do one simple thing, take data coming from a database query an use it
to populate pre-existing or dynamic objects
• Nothing more and nothing less
• No frills approach: Not identity mapping, no lazy load
• SQL *MUST* be written manually (no LINQ or other intermediate
language like HQL)
• Tries not to introduce friction when accessing and operating on data
One of the most used, proven and well-known is Dapper .NET
https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/
Why MicroORM?
You are interested in:
GET GREAT PERFORMANCE
REDUCE RESOURCE COSTS
BE IN CONTROL
Dapper .NET
First public release on Apr, 2011
Supports .NET “Classic” and .NET Core
Supports any RDBMS supported by .NET ADO providers: SQL Server, SQL
Lite, PostgreSQL, Oracle, MySQL, Firebird, …
Works as an extensions to IDBConnection interface
Installation via NuGet or dotnet add package
Dapper .NET
High performance Micro-ORM:
• YOU Create POCO classes
• YOU Write SQL
Map SQL results to POCO classes
• Automatically done 
Very Fast!
Where does performances come from?
DynamicMethod
• Inject MSIL directly in the body
of existing code
• Somehow like the “asm” keyword of C/C++
Allows mapping to POCO properties
without Reflection
• Almost no performance impact
• No more boring GetInt32()/GetString()/Get…() code 
Dapper .NET
Full source code available on GitHub
https://github.com/StackExchange/dapper-dot-net
Created and used by Stack Exchange
• Battle Tested! 
• Born here: How I learned to stop worrying and write my own ORM
Support available on GitHub and Stack Overflow:
http://stackoverflow.com/questions/tagged/dapper
The Basics
Dapper .NET
Dapper .NET
Extends the IDBConnection interface
Provides three main methods
• Query
• Execute
• ExecuteScalar
Dapper .NET
The three main methods are implemented in various ways
• To support Async/Await
• To support Single/First/FirstOrDefault
• To support multiple results set
• To support DataReaders
Results can be mapped to
• (Enumerable of) POCO classes
• (Enumerable of) dynamic objects
Parametric Queries
All methods support parametric queries.
Parameters are identified using the “@” symbol:
Parameters can be
• Anonymous Objects
• DynamicParameters Objects
• List (to support then IN clause)
SELECT [Id], [FirstName], [LastName]
FROM dbo.[Users] WHERE Id = @Id
Stored Procedures
Stored procedures can be executed easily
• Set CommandType to StoredProcedure
• Do not specify EXEC[UTE]
• Pass the parameters as shown before
• Return value and Output Parameters can be obtained via
DynamicParameters
• Result can be mapped to (Enumerable of) POCOs or Dynamic Objects just as an
ad-hoc query
The Basics
Demo
Advanced
Features
Dapper .NET
Multiple Execution
Use a IEnumerable parameter to execute the statement for each item.
• Only “Execute” Method supports this feature
var paramList = new List<DynamicParameters>();
paramList.Add(p1)
paramList.Add(p2)
paramList.Add(p3)
var affectedRows = conn.Execute(“<SQL>”, paramList)
Multiple Results
Mapping multiple result set to different object is also supported
“Read” is just like the “Query” method and supports all overloads and
specialized methods (eg: ReadFirst, ReadSingle, AsyncRead…)
using (var qm = conn.QueryMultiple(“SELECT…;SELECT…”))
{
var users = qm.Read<User>();
var companies = qm.Read<Company>();
}
Multiple Mapping
It’s also possible to take data from one row and split it in multiple objects
Table-Valued Parameters
Any IEnumerable or DataTable can be used. (As expected)
Use the extension method .AsTableValuedParameter
Special SQL Server Data Types
All ”special” SQL Server Data Types are supported:
• Geometry
• Geography
• HierarchyID
Just use them as usual
• Reference and Use Microsoft.SqlServer.Types
• Use them with Dapper as any other object
JSON
JSON in SQL Server is “just” text
Dapper deals with it as such, so Serialization and Deserialization must be
done manually
Customizing Interaction with database
There are two way to customize how Dapper will map data to and from
database:
• Mapping: Which property is mapped to column and vice-versa
• Handling: How property’s value is loaded into to database column and
vice-versa
Custom Data Mapping
It is possible to replace default “same name” convention mappings
Define mapping between model and database by creating a
CustomPropertyTypeMap
Make it active via SqlMapper.SetTypeMap
Custom Type Handling
Explicitly states how handling data between model and database should
happen
• Opens up a world of possibilities, to handle even the most complex
scenarios
SqlMapper is the object that behind the scenes does the mapping
• Can be used explicitly: SqlMapper.AddTypeHandler(<TypeHandler>)
Create your own type handler
• Create a class that derives from SqlMapper.TypeHandler
• Implement methods Parse and SetValue
Transactions
Transaction are supported via the usual:
• BeginTransaction
• TransactionScope
Buffered & Unbuffered results
By default the entire result set will be loaded in memory and then returned
to you
• The aim is to stay connected to the database for the smallest amount of
time possible
• Of course this means memory usage
In order to have the results usable as soon as they are streamed from the
database the “unbuffered” option exists
conn.Query("SELECT …;", buffered: false);
Advanced
Features
Demo
Extensions
Dapper .NET
Well-Known Extensions
A Growing Ecosystem! Extend Dapper features. Two main families:
• mainly adding CRUD support (by generating SQL on-the-fly)
• customize mapping db to class
A complete list is here:
• http://dapper-tutorial.net/dapper-contrib-third-party-library
ORM and micro-ORM
Now the question is: Is a MicroORM good for me?
If you need performance, know SQL and want/need to be in control of
everything: MicroORM is the way to go
• And, btw, for me, a (Backend) Developer *must* know SQL!
If you prefer more support with compile-time, object tracking, intellisense,
etc. and don’t want/need to write your own SQL: ORM is ok
A mix of the two is also possible if needed.
Conclusions & Alternatives
Other MicroORM you may want to take a look at
• ORMLite
• PetaPoco
• Massive
• Simple.Data
Session evaluations
Download the GuideBook App
and search: PASS Summit 2017
Follow the QR code link
displayed on session signage
throughout the conference
venue and in the program guide
Your feedback is important and valuable.
Go to passSummit.com
Submit by 5pm Friday, November 10th to win prizes. 3 Ways to Access:
Thank You
Learn more from Speaker Name
info@davidemauri.it@mauridb
Ad

More Related Content

What's hot (20)

Automata theory
Automata theoryAutomata theory
Automata theory
colleges
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 
Stream and Batch Processing in the Cloud with Data Microservices
Stream and Batch Processing in the Cloud with Data MicroservicesStream and Batch Processing in the Cloud with Data Microservices
Stream and Batch Processing in the Cloud with Data Microservices
marius_bogoevici
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
ShahDhruv21
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
Ravi_Kant_Sahu
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Hock Leng PUAH
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
shathika
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
desaipratu10
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
Soluto
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfFrom Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
José Paumard
 
B tree
B  treeB  tree
B tree
Fatimah Alqadheeb
 
Properties of Regular Expressions
Properties of Regular ExpressionsProperties of Regular Expressions
Properties of Regular Expressions
Shiraz316
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Philip Schwarz
 
Journey of saga pattern in microservice architecture
Journey of saga pattern in microservice architectureJourney of saga pattern in microservice architecture
Journey of saga pattern in microservice architecture
anisurrahman403160
 
Lecture 5 sorting and searching
Lecture 5   sorting and searchingLecture 5   sorting and searching
Lecture 5 sorting and searching
Nada G.Youssef
 
Spring Transaction Management
Spring Transaction ManagementSpring Transaction Management
Spring Transaction Management
Ye Win
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Automata theory
Automata theoryAutomata theory
Automata theory
colleges
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 
Stream and Batch Processing in the Cloud with Data Microservices
Stream and Batch Processing in the Cloud with Data MicroservicesStream and Batch Processing in the Cloud with Data Microservices
Stream and Batch Processing in the Cloud with Data Microservices
marius_bogoevici
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
Ravi_Kant_Sahu
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
shathika
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
desaipratu10
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
Soluto
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfFrom Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
José Paumard
 
Properties of Regular Expressions
Properties of Regular ExpressionsProperties of Regular Expressions
Properties of Regular Expressions
Shiraz316
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Philip Schwarz
 
Journey of saga pattern in microservice architecture
Journey of saga pattern in microservice architectureJourney of saga pattern in microservice architecture
Journey of saga pattern in microservice architecture
anisurrahman403160
 
Lecture 5 sorting and searching
Lecture 5   sorting and searchingLecture 5   sorting and searching
Lecture 5 sorting and searching
Nada G.Youssef
 
Spring Transaction Management
Spring Transaction ManagementSpring Transaction Management
Spring Transaction Management
Ye Win
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 

Similar to Dapper: the microORM that will change your life (20)

What is spatial sql
What is spatial sqlWhat is spatial sql
What is spatial sql
shawty_ds
 
Machine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy CrossMachine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy Cross
Andrew Flatters
 
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Calvin Tan
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdb
jixuan1989
 
Stackato v5
Stackato v5Stackato v5
Stackato v5
Jonas Brømsø
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics Applications
DataWorks Summit
 
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
The Hive
 
Vba Class Level 3
Vba Class Level 3Vba Class Level 3
Vba Class Level 3
Ben Miu CIM® FCSI A+
 
Mapping Life Science Informatics to the Cloud
Mapping Life Science Informatics to the CloudMapping Life Science Informatics to the Cloud
Mapping Life Science Informatics to the Cloud
Chris Dagdigian
 
Stackato v6
Stackato v6Stackato v6
Stackato v6
Jonas Brømsø
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
rajmundr
 
Stackato v3
Stackato v3Stackato v3
Stackato v3
Jonas Brømsø
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
Thomas Jaskula
 
Hofstra University - Overview of Big Data
Hofstra University - Overview of Big DataHofstra University - Overview of Big Data
Hofstra University - Overview of Big Data
sarasioux
 
Agile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics ApplicationsAgile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics Applications
Russell Jurney
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?
TheFamily
 
Server’s variations bsw2015
Server’s variations bsw2015Server’s variations bsw2015
Server’s variations bsw2015
Laurent Cerveau
 
From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)
From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)
From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)
Jernej Kavka (JK)
 
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
Thibaud Desodt
 
What is spatial sql
What is spatial sqlWhat is spatial sql
What is spatial sql
shawty_ds
 
Machine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy CrossMachine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy Cross
Andrew Flatters
 
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Calvin Tan
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdb
jixuan1989
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics Applications
DataWorks Summit
 
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
The Hive
 
Mapping Life Science Informatics to the Cloud
Mapping Life Science Informatics to the CloudMapping Life Science Informatics to the Cloud
Mapping Life Science Informatics to the Cloud
Chris Dagdigian
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
rajmundr
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
Thomas Jaskula
 
Hofstra University - Overview of Big Data
Hofstra University - Overview of Big DataHofstra University - Overview of Big Data
Hofstra University - Overview of Big Data
sarasioux
 
Agile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics ApplicationsAgile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics Applications
Russell Jurney
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?
TheFamily
 
Server’s variations bsw2015
Server’s variations bsw2015Server’s variations bsw2015
Server’s variations bsw2015
Laurent Cerveau
 
From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)
From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)
From Paper to Power using Azure Form Recognizer (Azure Sydney UG 2020)
Jernej Kavka (JK)
 
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
Thibaud Desodt
 
Ad

More from Davide Mauri (20)

Azure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstartAzure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstart
Davide Mauri
 
Agile Data Warehousing
Agile Data WarehousingAgile Data Warehousing
Agile Data Warehousing
Davide Mauri
 
When indexes are not enough
When indexes are not enoughWhen indexes are not enough
When indexes are not enough
Davide Mauri
 
Building a Real-Time IoT monitoring application with Azure
Building a Real-Time IoT monitoring application with AzureBuilding a Real-Time IoT monitoring application with Azure
Building a Real-Time IoT monitoring application with Azure
Davide Mauri
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep Dive
Davide Mauri
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSON
Davide Mauri
 
SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2
Davide Mauri
 
SQL Server 2016 Temporal Tables
SQL Server 2016 Temporal TablesSQL Server 2016 Temporal Tables
SQL Server 2016 Temporal Tables
Davide Mauri
 
SQL Server 2016 What's New For Developers
SQL Server 2016  What's New For DevelopersSQL Server 2016  What's New For Developers
SQL Server 2016 What's New For Developers
Davide Mauri
 
Azure Stream Analytics
Azure Stream AnalyticsAzure Stream Analytics
Azure Stream Analytics
Davide Mauri
 
Azure Machine Learning
Azure Machine LearningAzure Machine Learning
Azure Machine Learning
Davide Mauri
 
Dashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BIDashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BI
Davide Mauri
 
Azure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applicationsAzure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applications
Davide Mauri
 
Event Hub & Azure Stream Analytics
Event Hub & Azure Stream AnalyticsEvent Hub & Azure Stream Analytics
Event Hub & Azure Stream Analytics
Davide Mauri
 
SQL Server 2016 JSON
SQL Server 2016 JSONSQL Server 2016 JSON
SQL Server 2016 JSON
Davide Mauri
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep Dive
Davide Mauri
 
Real Time Power BI
Real Time Power BIReal Time Power BI
Real Time Power BI
Davide Mauri
 
AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)
Davide Mauri
 
Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)
Davide Mauri
 
Azure Machine Learning (Italian)
Azure Machine Learning (Italian)Azure Machine Learning (Italian)
Azure Machine Learning (Italian)
Davide Mauri
 
Azure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstartAzure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstart
Davide Mauri
 
Agile Data Warehousing
Agile Data WarehousingAgile Data Warehousing
Agile Data Warehousing
Davide Mauri
 
When indexes are not enough
When indexes are not enoughWhen indexes are not enough
When indexes are not enough
Davide Mauri
 
Building a Real-Time IoT monitoring application with Azure
Building a Real-Time IoT monitoring application with AzureBuilding a Real-Time IoT monitoring application with Azure
Building a Real-Time IoT monitoring application with Azure
Davide Mauri
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep Dive
Davide Mauri
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSON
Davide Mauri
 
SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2
Davide Mauri
 
SQL Server 2016 Temporal Tables
SQL Server 2016 Temporal TablesSQL Server 2016 Temporal Tables
SQL Server 2016 Temporal Tables
Davide Mauri
 
SQL Server 2016 What's New For Developers
SQL Server 2016  What's New For DevelopersSQL Server 2016  What's New For Developers
SQL Server 2016 What's New For Developers
Davide Mauri
 
Azure Stream Analytics
Azure Stream AnalyticsAzure Stream Analytics
Azure Stream Analytics
Davide Mauri
 
Azure Machine Learning
Azure Machine LearningAzure Machine Learning
Azure Machine Learning
Davide Mauri
 
Dashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BIDashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BI
Davide Mauri
 
Azure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applicationsAzure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applications
Davide Mauri
 
Event Hub & Azure Stream Analytics
Event Hub & Azure Stream AnalyticsEvent Hub & Azure Stream Analytics
Event Hub & Azure Stream Analytics
Davide Mauri
 
SQL Server 2016 JSON
SQL Server 2016 JSONSQL Server 2016 JSON
SQL Server 2016 JSON
Davide Mauri
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep Dive
Davide Mauri
 
Real Time Power BI
Real Time Power BIReal Time Power BI
Real Time Power BI
Davide Mauri
 
AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)
Davide Mauri
 
Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)
Davide Mauri
 
Azure Machine Learning (Italian)
Azure Machine Learning (Italian)Azure Machine Learning (Italian)
Azure Machine Learning (Italian)
Davide Mauri
 
Ad

Recently uploaded (20)

The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 

Dapper: the microORM that will change your life

  • 1. The micro-ORM that will change your life Davide Mauri, Director of Software Engineering, Sensoria Dapper .NET
  • 2. Please silence cell phones Please silence cell phones 2
  • 3. Free online webinar events Free 1-day local training events Local user groups around the world Online special interest user groups Business analytics training Free Online Resources PASS Blog White Papers Session Recordings Newsletter www.pass.org Explore everything PASS has to offer PASS Connector BA Insights Get involved
  • 4. Davide Mauri Director of Software Engineering, Sensoria A DEVELOPER 20 years in development, started with C++, then VB & Delphi, then C# and now also Python. Active on GitHub A DATABASE GUY 15 years spent on High-Performance Database, Data Warehouse, Business Intelligence and Business Analytics projects. Data Platform MVP since 2007 AGILE & AUTOMATION FAN Fan of Agile Methodology and Automation, I try to apply them everywhere he can, to make sure that "people think, machines do". IoT is where I live and work now, making sure the above two worlds work well together /davidemauri @mauridb http://www.sensoriafitness.com/
  • 5. Agenda • The story so far: DEV, DBA, ORM, MicroORM • Dapper.NET • Basic Usage • Advanced Stuff • Extensions • Conclusions
  • 6. Let’s start with a definition fric·tion The resistance that data finds when it moves from the application to the database or vice-versa The resistance that one surface or object encounters when moving over another. Friction is bad - It will slow your performance down - It will make your DBA scream - It will make your DEV scream - It will increase solution costs © http://becauseracecar.net
  • 7. Impedance Mismatch Friction exists because of the “Impedance Mismatch” • Object Oriented Models and Relational Models are different • Yet they have to co-exists since they are both really good at their job Friction also gets generated between teams (DBA vs DEV) • Code First or Database First? • Stored Procedure or SQL generated on the fly?
  • 8. What’s your current status? Beginner Advanced I really encourage you to share this presentation with your developers.
  • 9. The story so far… DEV usually don’t like to write (and in general deal with) databases, and SQL code especially • It looks old…wait: it IS old! • It’s not OO • It’s complex/strange/illogic • It’s really not part of my job So let’s have something to write the SQL code for us so we can just abstract from it • It will even make application work with any DB! That’s a strong selling point to give to my boss!
  • 10. The story so far… ORM (Object-Relational-Mapping) to the rescue • DEVs don’t write the code • DBAs still can’t put their hands in code but now is the ORM to blame Everyone is happy from a relationship perspective
  • 11. The story so far… Performance still crappy. Really crappy. Let’s move to a NoSQL db then. • It was cool in that presentation right? • No more normalization stuff….Ehy is the word “Normalization” that one I’m seeing in MongoDB docs? • Nice: no joins! Well uhm…but now we have *a lot* of duplication in our data. • But the fact that I can just put and get my class is soooooo cool and comfortable. • The DBA will figure out later how the extract data from it and if the data has some logical meaning or not. Even in which property the data is stored. Damn! Someone created the InvoiceValue property but we already had the InvoceAmout to be used. Oh well, let’s add an if, no, better!, let’s create a solution that via IoC that allows us to configure where I have to look for Invoice amount. Great let’s do that for all the other fields too!
  • 12. The story so far… ORM like EF or NHibernate wrote the SQL code on the fly • No why to change it if at some point you discover it could have been written so much better It would be nice if one could just behave like if the SQL code doesn’t exists: the DBA will write the code for me and I just map it to my OO objects • Which is boring anyway. • There is a tool that, given a query in can automatically map the result into an OO object of mine?
  • 13. The story so far… Devs recently come to realize that – an average - they need to use a DB to excel in their job • DB is quite cool again. Lock-Free tables, columnar storage, cool uh? Still writing interacting with the db is boring (which means error prone) • Create the connection • Execute the query • Map the query to OO objects • Close the connection • Oh wait, yeah, exception management
  • 14. The story so far… DBA they want to be able to Improve, Fix, Cleanup, Tweak SQL code written by DEVs. • Because if the db is slow it’s THEIR problem, even if they DIDN’T wrote that code. • But actually they don’t really want to touch DEVs code….is so dirty! And it’s barely comprehensible. And look how he wrote this statement, oh my gosh, this prevents index to be used, geez! Look: my poor server is just out of CPU and I/O! • Phone calls. It’s the customer care complaining that they cannot do their job, everything is slow
  • 15. What a MicroORM is? Just do one simple thing, take data coming from a database query an use it to populate pre-existing or dynamic objects • Nothing more and nothing less • No frills approach: Not identity mapping, no lazy load • SQL *MUST* be written manually (no LINQ or other intermediate language like HQL) • Tries not to introduce friction when accessing and operating on data One of the most used, proven and well-known is Dapper .NET https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/
  • 16. Why MicroORM? You are interested in: GET GREAT PERFORMANCE REDUCE RESOURCE COSTS BE IN CONTROL
  • 17. Dapper .NET First public release on Apr, 2011 Supports .NET “Classic” and .NET Core Supports any RDBMS supported by .NET ADO providers: SQL Server, SQL Lite, PostgreSQL, Oracle, MySQL, Firebird, … Works as an extensions to IDBConnection interface Installation via NuGet or dotnet add package
  • 18. Dapper .NET High performance Micro-ORM: • YOU Create POCO classes • YOU Write SQL Map SQL results to POCO classes • Automatically done  Very Fast!
  • 19. Where does performances come from? DynamicMethod • Inject MSIL directly in the body of existing code • Somehow like the “asm” keyword of C/C++ Allows mapping to POCO properties without Reflection • Almost no performance impact • No more boring GetInt32()/GetString()/Get…() code 
  • 20. Dapper .NET Full source code available on GitHub https://github.com/StackExchange/dapper-dot-net Created and used by Stack Exchange • Battle Tested!  • Born here: How I learned to stop worrying and write my own ORM Support available on GitHub and Stack Overflow: http://stackoverflow.com/questions/tagged/dapper
  • 22. Dapper .NET Extends the IDBConnection interface Provides three main methods • Query • Execute • ExecuteScalar
  • 23. Dapper .NET The three main methods are implemented in various ways • To support Async/Await • To support Single/First/FirstOrDefault • To support multiple results set • To support DataReaders Results can be mapped to • (Enumerable of) POCO classes • (Enumerable of) dynamic objects
  • 24. Parametric Queries All methods support parametric queries. Parameters are identified using the “@” symbol: Parameters can be • Anonymous Objects • DynamicParameters Objects • List (to support then IN clause) SELECT [Id], [FirstName], [LastName] FROM dbo.[Users] WHERE Id = @Id
  • 25. Stored Procedures Stored procedures can be executed easily • Set CommandType to StoredProcedure • Do not specify EXEC[UTE] • Pass the parameters as shown before • Return value and Output Parameters can be obtained via DynamicParameters • Result can be mapped to (Enumerable of) POCOs or Dynamic Objects just as an ad-hoc query
  • 28. Multiple Execution Use a IEnumerable parameter to execute the statement for each item. • Only “Execute” Method supports this feature var paramList = new List<DynamicParameters>(); paramList.Add(p1) paramList.Add(p2) paramList.Add(p3) var affectedRows = conn.Execute(“<SQL>”, paramList)
  • 29. Multiple Results Mapping multiple result set to different object is also supported “Read” is just like the “Query” method and supports all overloads and specialized methods (eg: ReadFirst, ReadSingle, AsyncRead…) using (var qm = conn.QueryMultiple(“SELECT…;SELECT…”)) { var users = qm.Read<User>(); var companies = qm.Read<Company>(); }
  • 30. Multiple Mapping It’s also possible to take data from one row and split it in multiple objects
  • 31. Table-Valued Parameters Any IEnumerable or DataTable can be used. (As expected) Use the extension method .AsTableValuedParameter
  • 32. Special SQL Server Data Types All ”special” SQL Server Data Types are supported: • Geometry • Geography • HierarchyID Just use them as usual • Reference and Use Microsoft.SqlServer.Types • Use them with Dapper as any other object
  • 33. JSON JSON in SQL Server is “just” text Dapper deals with it as such, so Serialization and Deserialization must be done manually
  • 34. Customizing Interaction with database There are two way to customize how Dapper will map data to and from database: • Mapping: Which property is mapped to column and vice-versa • Handling: How property’s value is loaded into to database column and vice-versa
  • 35. Custom Data Mapping It is possible to replace default “same name” convention mappings Define mapping between model and database by creating a CustomPropertyTypeMap Make it active via SqlMapper.SetTypeMap
  • 36. Custom Type Handling Explicitly states how handling data between model and database should happen • Opens up a world of possibilities, to handle even the most complex scenarios SqlMapper is the object that behind the scenes does the mapping • Can be used explicitly: SqlMapper.AddTypeHandler(<TypeHandler>) Create your own type handler • Create a class that derives from SqlMapper.TypeHandler • Implement methods Parse and SetValue
  • 37. Transactions Transaction are supported via the usual: • BeginTransaction • TransactionScope
  • 38. Buffered & Unbuffered results By default the entire result set will be loaded in memory and then returned to you • The aim is to stay connected to the database for the smallest amount of time possible • Of course this means memory usage In order to have the results usable as soon as they are streamed from the database the “unbuffered” option exists conn.Query("SELECT …;", buffered: false);
  • 41. Well-Known Extensions A Growing Ecosystem! Extend Dapper features. Two main families: • mainly adding CRUD support (by generating SQL on-the-fly) • customize mapping db to class A complete list is here: • http://dapper-tutorial.net/dapper-contrib-third-party-library
  • 42. ORM and micro-ORM Now the question is: Is a MicroORM good for me? If you need performance, know SQL and want/need to be in control of everything: MicroORM is the way to go • And, btw, for me, a (Backend) Developer *must* know SQL! If you prefer more support with compile-time, object tracking, intellisense, etc. and don’t want/need to write your own SQL: ORM is ok A mix of the two is also possible if needed.
  • 43. Conclusions & Alternatives Other MicroORM you may want to take a look at • ORMLite • PetaPoco • Massive • Simple.Data
  • 44. Session evaluations Download the GuideBook App and search: PASS Summit 2017 Follow the QR code link displayed on session signage throughout the conference venue and in the program guide Your feedback is important and valuable. Go to passSummit.com Submit by 5pm Friday, November 10th to win prizes. 3 Ways to Access:
  • 45. Thank You Learn more from Speaker Name [email protected]@mauridb