SlideShare a Scribd company logo
.NET Database Toolkit
Dapper, Spritely.Cqrs, AutoMapper, FluentMigrator
What is Dapper?
A “micro-ORM” written by these guys…
Sam Saffron Marc Gravell
What is an ORM?
 From Wikipedia: Object-relational mapping (ORM, O/RM, and O/R mapping) in
computer science is a programming technique for converting data between
incompatible type systems in object-oriented programming languages.
 Challenges
 There are a variety of difficulties that arise when considering how to match an object
system to a relational database.
 An alternative to implementing ORM is use of the native procedural languages provided
with every major database on the market. The Data Access Object (DAO) design pattern
is used to abstract these statements and offer a lightweight object-oriented interface to
the rest of the application
 Examples
 Entity Framework
 NHibernate
What is CQ[R]S?
 From Wikipedia: Command–query separation (CQS) is a principle
of imperative computer programming. It was devised by Bertrand Meyer as part of
his pioneering work on the Eiffel programming language.
 It states that every method should either be a command that performs an action,
or a query that returns data to the caller, but not both. In other words, Asking a
question should not change the answer. More formally, methods should return a
value only if they are referentially transparent and hence possess no side effects.
 Offers:
 Easier scaling (easy to manage read replicas).
 Easier testing (easy to mock out each call explicitly).
 I’m using interfaces from NuGet package: Spritely.Cqrs.
 The “query” or “command” class is the parameter object (can have zero
properties).
 The handler class has the behavior and is what gets mocked during testing.
// arrange
var expectedThing = new ThingDataAccessObject() { Id = 0, Values = "Monkey" };
var thingMap = new Dictionary<int, ThingDataAccessObject> {
{ expectedThing.Id, expectedThing } };
var mockGetThingByIdQueryHandler = new
Mock<IQueryHandler<GetThingByIdQuery, ThingDataAccessObject>>();
mockGetThingByIdQueryHandler
.Setup(_ => _.Handle(It.IsAny<GetThingByIdQuery>()))
.Returns<GetThingByIdQuery>(query => thingMap[query.ThingId]);
var service = new ThingWcfService(mockGetThingByIdQueryHandler.Object);
// act
var actualThing = service.GetThing(expectedThing.Id);
// assert
Assert.Equal(expectedThing.ToThingWcfObject().Id, actualThing.Id);
Assert.Equal(expectedThing.ToThingWcfObject().Values, actualThing.Values);
// - make sure we're testing all of the properties
Assert.Equal(2, typeof(ThingWcfObject).GetProperties().Count());
Testing with CQRS
Ok, what is Dapper?
 From Wikipedia: Dapper was started by Sam Saffron and Marc
Gravell because of the N+1 and other performance issues with Entity
framework. Dapper was written for and is used by Stack Overflow.
 Dapper's primary feature is mapping from .NET classes to database tables
(and from CLR data types to SQL data types). Dapper also provides data query
and retrieval facilities.
 Dapper is a micro-ORM: it does not offer the full range of features of a full
ORM such as nHibernate or Entity Framework. This is by design. Dapper does
not generate the SQL queries, but only maps the result to Plain Old CLR
Objects (POCOs).
 The single class ORM is also available on NuGet.
What about performance?
ADO.Net vs. Dapper – First the CQRS Part
public class GetThingByIdQuery : IQuery<ThingDataAccessObject>
{
public int ThingId { get; set; }
}
public class GetThingByIdQueryHandler :
IQueryHandler<GetThingByIdQuery, ThingDataAccessObject>
{
private readonly string connectionString;
public GetThingByIdQueryHandler(string connectionstring)
{
this.connectionString = connectionstring;
}
public ThingDataAccessObject Handle(GetThingByIdQuery query)
{
Basic CQRS…
• Class for params (the ‘Query’)
• Class for behavior (the
‘QueryHandler’)
ADO.Net vs. Dapper – What they share
Pretty standard fare…
• Using SQL is a good thing because
you can optimize for the database
engine’s provided advantages.
• Use parameterized SQL to prevent
injection…
ThingDataAccessObject ret = null;
var sqlText = @"SELECT ThingId as [Id],
[Values] as [Values]
FROM Thing
WHERE ThingId = @ThingId";
using (IDbConnection connection = new SqlConnection(this.connectionString))
{
connection.Open();
ADO.Net Version
Really not that bad…
• It is a little bit of boiler plate
code though which is a pain
var command = connection.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = sqlText;
command.Parameters.Add(new SqlParameter("ThingId", query.ThingId));
using (var reader = command.ExecuteReader())
{
reader.Read();
ret = new ThingDataAccessObject
{
Id = reader.GetInt32(0),
Values = reader.GetString(1)
};
}
Dapper Version
This should really sell itself…
• Dapper is just that easy!
ret = connection
.Query<ThingDataAccessObject>(sqlText, query)
.SingleOrDefault();
What is AutoMapper?
 AutoMapper is a package on Nuget (Id=AutoMapper)
 A convention-based object-object mapper.
 Uses a fluent configuration API to define an object-object mapping strategy
and uses a convention-based matching algorithm to match up source to
destination values.
 Geared towards model projection scenarios to flatten complex object models
to DTOs and other simple objects, whose design is better suited for
serialization, communication, messaging, or simply an anti-corruption layer
between the domain and application layer.
So you have this in your world…
• This is normal!
• Don’t ever just use only the
EntityFramework class in all
layers no matter what anyone
tells you!
• These objects are contracts in
their own systems.
public class ThingDatabaseObject
{
public int Id { get; set; }
public string Values { get; set; }
}
public class ThingDataAccessObject
{
public int Id { get; set; }
public string Values { get; set; }
}
public class ThingWcfObject
{
public int Id { get; set; }
public string Values { get; set; }
}
public class ThingRestObject
{
public int Id { get; set; }
public string Values { get; set; }
}
So you have this in your world…
• This is actually a pretty high overhead, but historically kind of a necessary evil…
public static ThingDataAccessObject ToDataAccessObject(this ThingDatabaseObject source)
{
return new ThingDataAccessObject { Id = source.Id, Values = source.Values };
}
public static ThingWcfObject ToThingWcfObject(this ThingDataAccessObject source)
{
return new ThingWcfObject { Id = source.Id, Values = source.Values };
}
public static ThingRestObject ToThingRestObject(this ThingDataAccessObject source)
{
return new ThingRestObject { Id = source.Id, Values = source.Values };
}
And you aslo have this in your world…
• These tests add to the high overhead…
public class ThingConversionExtensionMethodsTests
{
[Fact]
public static void ToDataAccessObject_InputAllPropsSet_OutputAllPropsMatch()
{
// arrange
var objectIn = new ThingDatabaseObject() { Id = 4, Values = "SomeValues" };
// act
var objectOut = objectIn.ToDataAccessObject();
// assert
Assert.Equal(objectIn.Id, objectOut.Id);
Assert.Equal(objectIn.Values, objectOut.Values);
// - make sure we know all the properties to test
Assert.Equal(2, typeof(ThingDatabaseObject).GetProperties().Count());
Assert.Equal(2, typeof(ThingWcfObject).GetProperties().Count());
}
Mapper.CreateMap<ThingDataAccessObject, ThingWcfObject>();
Mapper.AssertConfigurationIsValid();
NOW you have this in your world…
• This is better!
• Easy overhead and if you need special mappings
there is a ton of extensibility and all in one place…
There’s really not much difference…
• There is a little overhead on use with
AutoMapper.
• There is much more overhead with extension
methods to convert.
• The extension method version reads a little
nicer
• The AutoMapper version wins just for speed of
coding…
public class ThingWcfService
{
static ThingWcfService()
{
RunDiagnostics();
}
public static void RunDiagnostics()
{
Mapper.CreateMap<ThingDataAccessObject, ThingWcfObject>();
Mapper.AssertConfigurationIsValid();
}
public ThingWcfObject GetThing(int id)
{
var dao = ThingDataAccess.GetThingById(id);
var extMethodRet = dao.ToThingWcfObject();
var autoMapperRet = Mapper.Map<ThingWcfObject>(dao);
What is Fluent Migrator?
 A NuGet package that allows you manage your database migrations in .NET
source control with supported tooling.
 Modeled after the Ruby style of database migrations.
 You need this because otherwise you’re probably in one of these camps:
 We just re-script from production because we have no DB source we trust.
 We suffer EntityFramework because then we always have DB source checked in.
 We have some custom complicated process of keeping alter scripts in a structure.
Each Migration is a class
[Migration(Versions.BaseMigrationVersion)]
public class ThingDatabaseInitialMigration : Migration
{
public class Versions
{
public const long BaseMigrationVersion = 0;
}
Create a class like so…
• I use a class to hold the versions used in the
attribute as a convenience.
Migrations have Migrate “Up” and “Down”
Perform your database operations…
• The fluent grammar makes it really nice to
declare items, add seed data, remove
unneeded items, and easy to port to other
Database Types.
• Can also just run raw SQL like for creating
StoredProcedures.
public static ThingDatabaseObject SeedData = new ThingDatabaseObject()
{ Id = 0, Values = "Monkey" };
public override void Up()
{
Create.Table("Thing")
.WithColumn("ThingId")
.AsInt32()
.PrimaryKey()
.WithColumn("Values")
.AsString();
Insert.IntoTable("Thing").Row(SeedData);
}
public override void Down()
{
Delete.Table("WorkingTranslate_v1");
}
Easy to Execute
Naos.Database.Migrator.MigrationExecutor.Up(
typeof(ThingDatabaseInitialMigration).Assembly,
connectionString,
dbName,
ThingDatabaseInitialMigration.Versions.BaseMigrationVersion,
Console.WriteLine);
Run through the runner…
• There is a command line exe that ships native
with the FluentMigrator package in NuGet.
• Naos.Database.Migrator is a thin wrapper
around the FluentMigrator Protocol and
available in NuGet.
• Can also execute in preview mode and just
show the SQL to apply.
Links
 Author: Lawson Caudill – http://www.getthinktank.com
 Code in deck is available at – https://github.com/wlscaudill/Presentation---
.NET-Database-Toolkit
 https://github.com/StackExchange/dapper-dot-net
 http://samsaffron.com
 http://marcgravell.blogspot.com/
 http://en.wikipedia.org/wiki/Object-relational_mapping
 https://www.nuget.org/packages/Spritely.Cqrs/
 https://www.nuget.org/packages/AutoMapper/
 https://github.com/schambers/fluentmigrator
 https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=92

More Related Content

What's hot

Hibernate
HibernateHibernate
Using Xcore with Xtext
Using Xcore with XtextUsing Xcore with Xtext
Using Xcore with Xtext
Holger Schill
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
Booch Lin
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest Matchers
Shai Yallin
 
Aspect oriented programming with spring
Aspect oriented programming with springAspect oriented programming with spring
Aspect oriented programming with spring
Sreenivas Kappala
 
Effective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's bookEffective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's book
Roman Tsypuk
 
EMF Tips n Tricks
EMF Tips n TricksEMF Tips n Tricks
EMF Tips n Tricks
Kaniska Mandal
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
e-Legion
 
Green dao
Green daoGreen dao
Green dao
彥彬 洪
 
Static analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutesStatic analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutes
Andrey Karpov
 
Clean code with google guava jee conf
Clean code with google guava jee confClean code with google guava jee conf
Clean code with google guava jee conf
Igor Anishchenko
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
Andrey Karpov
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
Nguyen Cao
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
Tomas Jansson
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
Svetlin Nakov
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
Fahad Shaikh
 

What's hot (20)

Hibernate
HibernateHibernate
Hibernate
 
Green dao
Green daoGreen dao
Green dao
 
Using Xcore with Xtext
Using Xcore with XtextUsing Xcore with Xtext
Using Xcore with Xtext
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Lecture 3-ARC
Lecture 3-ARCLecture 3-ARC
Lecture 3-ARC
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest Matchers
 
Aspect oriented programming with spring
Aspect oriented programming with springAspect oriented programming with spring
Aspect oriented programming with spring
 
Effective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's bookEffective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's book
 
EMF Tips n Tricks
EMF Tips n TricksEMF Tips n Tricks
EMF Tips n Tricks
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
 
Green dao
Green daoGreen dao
Green dao
 
Static analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutesStatic analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutes
 
Clean code with google guava jee conf
Clean code with google guava jee confClean code with google guava jee conf
Clean code with google guava jee conf
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 

Viewers also liked

Entity framework introduction sesion-1
Entity framework introduction   sesion-1Entity framework introduction   sesion-1
Entity framework introduction sesion-1
Usama Nada
 
Building High Performance Websites - Session-1
Building High Performance Websites - Session-1Building High Performance Websites - Session-1
Building High Performance Websites - Session-1
Usama Nada
 
Intro to AWS
Intro to AWSIntro to AWS
Intro to AWS
wlscaudill
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
wlscaudill
 
Intro to Cloud Architecture
Intro to Cloud ArchitectureIntro to Cloud Architecture
Intro to Cloud Architecture
wlscaudill
 
Dapper & Dapper.SimpleCRUD
Dapper & Dapper.SimpleCRUDDapper & Dapper.SimpleCRUD
Dapper & Dapper.SimpleCRUD
Blank Chen
 
Dapper
DapperDapper
Intro to Stylecop
Intro to StylecopIntro to Stylecop
Intro to Stylecop
wlscaudill
 
Intro to NuGet
Intro to NuGetIntro to NuGet
Intro to NuGet
wlscaudill
 
Object Relational Mapping with Dapper (Micro ORM)
Object Relational Mapping with Dapper (Micro ORM)Object Relational Mapping with Dapper (Micro ORM)
Object Relational Mapping with Dapper (Micro ORM)
Muhammad Umar
 
A Scalable, Commodity Data Center Network Architecture
A Scalable, Commodity Data Center Network ArchitectureA Scalable, Commodity Data Center Network Architecture
A Scalable, Commodity Data Center Network Architecture
Gunawan Jusuf
 
AWS Network Topology/Architecture
AWS Network Topology/ArchitectureAWS Network Topology/Architecture
AWS Network Topology/Architecture
wlscaudill
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 

Viewers also liked (14)

Entity framework introduction sesion-1
Entity framework introduction   sesion-1Entity framework introduction   sesion-1
Entity framework introduction sesion-1
 
Building High Performance Websites - Session-1
Building High Performance Websites - Session-1Building High Performance Websites - Session-1
Building High Performance Websites - Session-1
 
Intro to AWS
Intro to AWSIntro to AWS
Intro to AWS
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
 
Intro to Cloud Architecture
Intro to Cloud ArchitectureIntro to Cloud Architecture
Intro to Cloud Architecture
 
Dapper & Dapper.SimpleCRUD
Dapper & Dapper.SimpleCRUDDapper & Dapper.SimpleCRUD
Dapper & Dapper.SimpleCRUD
 
Dapper
DapperDapper
Dapper
 
Intro to Stylecop
Intro to StylecopIntro to Stylecop
Intro to Stylecop
 
Intro to NuGet
Intro to NuGetIntro to NuGet
Intro to NuGet
 
Object Relational Mapping with Dapper (Micro ORM)
Object Relational Mapping with Dapper (Micro ORM)Object Relational Mapping with Dapper (Micro ORM)
Object Relational Mapping with Dapper (Micro ORM)
 
A Scalable, Commodity Data Center Network Architecture
A Scalable, Commodity Data Center Network ArchitectureA Scalable, Commodity Data Center Network Architecture
A Scalable, Commodity Data Center Network Architecture
 
AWS Network Topology/Architecture
AWS Network Topology/ArchitectureAWS Network Topology/Architecture
AWS Network Topology/Architecture
 
Software Development Life Cycle (SDLC)
Software Development Life Cycle (SDLC)Software Development Life Cycle (SDLC)
Software Development Life Cycle (SDLC)
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 

Similar to .NET Database Toolkit

Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
Juan Pablo
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
AntoJoseph36
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
Haroon Idrees
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015
Svetlin Nakov
 
Big-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbaiBig-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbai
Unmesh Baile
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
Thodoris Bais
 
Apache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster ComputingApache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster Computing
Gerger
 
Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5
Rainer Stropek
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#
Vagif Abilov
 
Bigger Stronger Faster
Bigger Stronger FasterBigger Stronger Faster
Bigger Stronger Faster
Chris Love
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
Christian Melchior
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays
 
Thunderstruck
ThunderstruckThunderstruck
Thunderstruck
wagnerandrade
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Vitaly Gordon
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
Ahmad Arif Faizin
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
Leonid Maslov
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
Alex Hardman
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 

Similar to .NET Database Toolkit (20)

Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015
 
Big-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbaiBig-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbai
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
 
Apache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster ComputingApache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster Computing
 
Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#
 
Bigger Stronger Faster
Bigger Stronger FasterBigger Stronger Faster
Bigger Stronger Faster
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
 
Thunderstruck
ThunderstruckThunderstruck
Thunderstruck
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 

Recently uploaded

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 

Recently uploaded (20)

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 

.NET Database Toolkit

  • 1. .NET Database Toolkit Dapper, Spritely.Cqrs, AutoMapper, FluentMigrator
  • 2. What is Dapper? A “micro-ORM” written by these guys… Sam Saffron Marc Gravell
  • 3. What is an ORM?  From Wikipedia: Object-relational mapping (ORM, O/RM, and O/R mapping) in computer science is a programming technique for converting data between incompatible type systems in object-oriented programming languages.  Challenges  There are a variety of difficulties that arise when considering how to match an object system to a relational database.  An alternative to implementing ORM is use of the native procedural languages provided with every major database on the market. The Data Access Object (DAO) design pattern is used to abstract these statements and offer a lightweight object-oriented interface to the rest of the application  Examples  Entity Framework  NHibernate
  • 4. What is CQ[R]S?  From Wikipedia: Command–query separation (CQS) is a principle of imperative computer programming. It was devised by Bertrand Meyer as part of his pioneering work on the Eiffel programming language.  It states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, Asking a question should not change the answer. More formally, methods should return a value only if they are referentially transparent and hence possess no side effects.  Offers:  Easier scaling (easy to manage read replicas).  Easier testing (easy to mock out each call explicitly).  I’m using interfaces from NuGet package: Spritely.Cqrs.  The “query” or “command” class is the parameter object (can have zero properties).  The handler class has the behavior and is what gets mocked during testing.
  • 5. // arrange var expectedThing = new ThingDataAccessObject() { Id = 0, Values = "Monkey" }; var thingMap = new Dictionary<int, ThingDataAccessObject> { { expectedThing.Id, expectedThing } }; var mockGetThingByIdQueryHandler = new Mock<IQueryHandler<GetThingByIdQuery, ThingDataAccessObject>>(); mockGetThingByIdQueryHandler .Setup(_ => _.Handle(It.IsAny<GetThingByIdQuery>())) .Returns<GetThingByIdQuery>(query => thingMap[query.ThingId]); var service = new ThingWcfService(mockGetThingByIdQueryHandler.Object); // act var actualThing = service.GetThing(expectedThing.Id); // assert Assert.Equal(expectedThing.ToThingWcfObject().Id, actualThing.Id); Assert.Equal(expectedThing.ToThingWcfObject().Values, actualThing.Values); // - make sure we're testing all of the properties Assert.Equal(2, typeof(ThingWcfObject).GetProperties().Count()); Testing with CQRS
  • 6. Ok, what is Dapper?  From Wikipedia: Dapper was started by Sam Saffron and Marc Gravell because of the N+1 and other performance issues with Entity framework. Dapper was written for and is used by Stack Overflow.  Dapper's primary feature is mapping from .NET classes to database tables (and from CLR data types to SQL data types). Dapper also provides data query and retrieval facilities.  Dapper is a micro-ORM: it does not offer the full range of features of a full ORM such as nHibernate or Entity Framework. This is by design. Dapper does not generate the SQL queries, but only maps the result to Plain Old CLR Objects (POCOs).  The single class ORM is also available on NuGet.
  • 8. ADO.Net vs. Dapper – First the CQRS Part public class GetThingByIdQuery : IQuery<ThingDataAccessObject> { public int ThingId { get; set; } } public class GetThingByIdQueryHandler : IQueryHandler<GetThingByIdQuery, ThingDataAccessObject> { private readonly string connectionString; public GetThingByIdQueryHandler(string connectionstring) { this.connectionString = connectionstring; } public ThingDataAccessObject Handle(GetThingByIdQuery query) { Basic CQRS… • Class for params (the ‘Query’) • Class for behavior (the ‘QueryHandler’)
  • 9. ADO.Net vs. Dapper – What they share Pretty standard fare… • Using SQL is a good thing because you can optimize for the database engine’s provided advantages. • Use parameterized SQL to prevent injection… ThingDataAccessObject ret = null; var sqlText = @"SELECT ThingId as [Id], [Values] as [Values] FROM Thing WHERE ThingId = @ThingId"; using (IDbConnection connection = new SqlConnection(this.connectionString)) { connection.Open();
  • 10. ADO.Net Version Really not that bad… • It is a little bit of boiler plate code though which is a pain var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = sqlText; command.Parameters.Add(new SqlParameter("ThingId", query.ThingId)); using (var reader = command.ExecuteReader()) { reader.Read(); ret = new ThingDataAccessObject { Id = reader.GetInt32(0), Values = reader.GetString(1) }; }
  • 11. Dapper Version This should really sell itself… • Dapper is just that easy! ret = connection .Query<ThingDataAccessObject>(sqlText, query) .SingleOrDefault();
  • 12. What is AutoMapper?  AutoMapper is a package on Nuget (Id=AutoMapper)  A convention-based object-object mapper.  Uses a fluent configuration API to define an object-object mapping strategy and uses a convention-based matching algorithm to match up source to destination values.  Geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited for serialization, communication, messaging, or simply an anti-corruption layer between the domain and application layer.
  • 13. So you have this in your world… • This is normal! • Don’t ever just use only the EntityFramework class in all layers no matter what anyone tells you! • These objects are contracts in their own systems. public class ThingDatabaseObject { public int Id { get; set; } public string Values { get; set; } } public class ThingDataAccessObject { public int Id { get; set; } public string Values { get; set; } } public class ThingWcfObject { public int Id { get; set; } public string Values { get; set; } } public class ThingRestObject { public int Id { get; set; } public string Values { get; set; } }
  • 14. So you have this in your world… • This is actually a pretty high overhead, but historically kind of a necessary evil… public static ThingDataAccessObject ToDataAccessObject(this ThingDatabaseObject source) { return new ThingDataAccessObject { Id = source.Id, Values = source.Values }; } public static ThingWcfObject ToThingWcfObject(this ThingDataAccessObject source) { return new ThingWcfObject { Id = source.Id, Values = source.Values }; } public static ThingRestObject ToThingRestObject(this ThingDataAccessObject source) { return new ThingRestObject { Id = source.Id, Values = source.Values }; }
  • 15. And you aslo have this in your world… • These tests add to the high overhead… public class ThingConversionExtensionMethodsTests { [Fact] public static void ToDataAccessObject_InputAllPropsSet_OutputAllPropsMatch() { // arrange var objectIn = new ThingDatabaseObject() { Id = 4, Values = "SomeValues" }; // act var objectOut = objectIn.ToDataAccessObject(); // assert Assert.Equal(objectIn.Id, objectOut.Id); Assert.Equal(objectIn.Values, objectOut.Values); // - make sure we know all the properties to test Assert.Equal(2, typeof(ThingDatabaseObject).GetProperties().Count()); Assert.Equal(2, typeof(ThingWcfObject).GetProperties().Count()); }
  • 16. Mapper.CreateMap<ThingDataAccessObject, ThingWcfObject>(); Mapper.AssertConfigurationIsValid(); NOW you have this in your world… • This is better! • Easy overhead and if you need special mappings there is a ton of extensibility and all in one place…
  • 17. There’s really not much difference… • There is a little overhead on use with AutoMapper. • There is much more overhead with extension methods to convert. • The extension method version reads a little nicer • The AutoMapper version wins just for speed of coding… public class ThingWcfService { static ThingWcfService() { RunDiagnostics(); } public static void RunDiagnostics() { Mapper.CreateMap<ThingDataAccessObject, ThingWcfObject>(); Mapper.AssertConfigurationIsValid(); } public ThingWcfObject GetThing(int id) { var dao = ThingDataAccess.GetThingById(id); var extMethodRet = dao.ToThingWcfObject(); var autoMapperRet = Mapper.Map<ThingWcfObject>(dao);
  • 18. What is Fluent Migrator?  A NuGet package that allows you manage your database migrations in .NET source control with supported tooling.  Modeled after the Ruby style of database migrations.  You need this because otherwise you’re probably in one of these camps:  We just re-script from production because we have no DB source we trust.  We suffer EntityFramework because then we always have DB source checked in.  We have some custom complicated process of keeping alter scripts in a structure.
  • 19. Each Migration is a class [Migration(Versions.BaseMigrationVersion)] public class ThingDatabaseInitialMigration : Migration { public class Versions { public const long BaseMigrationVersion = 0; } Create a class like so… • I use a class to hold the versions used in the attribute as a convenience.
  • 20. Migrations have Migrate “Up” and “Down” Perform your database operations… • The fluent grammar makes it really nice to declare items, add seed data, remove unneeded items, and easy to port to other Database Types. • Can also just run raw SQL like for creating StoredProcedures. public static ThingDatabaseObject SeedData = new ThingDatabaseObject() { Id = 0, Values = "Monkey" }; public override void Up() { Create.Table("Thing") .WithColumn("ThingId") .AsInt32() .PrimaryKey() .WithColumn("Values") .AsString(); Insert.IntoTable("Thing").Row(SeedData); } public override void Down() { Delete.Table("WorkingTranslate_v1"); }
  • 21. Easy to Execute Naos.Database.Migrator.MigrationExecutor.Up( typeof(ThingDatabaseInitialMigration).Assembly, connectionString, dbName, ThingDatabaseInitialMigration.Versions.BaseMigrationVersion, Console.WriteLine); Run through the runner… • There is a command line exe that ships native with the FluentMigrator package in NuGet. • Naos.Database.Migrator is a thin wrapper around the FluentMigrator Protocol and available in NuGet. • Can also execute in preview mode and just show the SQL to apply.
  • 22. Links  Author: Lawson Caudill – http://www.getthinktank.com  Code in deck is available at – https://github.com/wlscaudill/Presentation--- .NET-Database-Toolkit  https://github.com/StackExchange/dapper-dot-net  http://samsaffron.com  http://marcgravell.blogspot.com/  http://en.wikipedia.org/wiki/Object-relational_mapping  https://www.nuget.org/packages/Spritely.Cqrs/  https://www.nuget.org/packages/AutoMapper/  https://github.com/schambers/fluentmigrator  https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=92