SlideShare a Scribd company logo
1 of 32
Download to read offline
Don't overcomplicate Introduction to Micro ORM Ivan Korneliuk @korneliuk http://korneliuk.blogspot.com/ 31337 Kiev ALT.NET
What wrong with ORM? ,[object Object],[object Object],[object Object],[object Object]
Micro ORM ,[object Object],[object Object],[object Object],[object Object]
dapper-dot-net Simple SQL object mapper for ADO.NET ,[object Object],[object Object],[object Object],[object Object],[object Object]
dapper-dot-net Main concepts ,[object Object],[object Object]
dapper-dot-net Querying POCOs public   class  Dog  {   public   int ? Age  {  get ;  set ;   }   public  Guid Id  {  get ;  set ;   }   public   string  Name  {  get ;  set ;   }   public   float ? Weight  {  get ;  set ;   }   public   int  IgnoredProperty  {  get  {   return   1 ;   }   }   }   var guid  =  Guid . NewGuid () ;   var dog  =  connection . Query < Dog >( &quot; select Age = @Age, Id = @Id &quot; ,   new   {  Age  =   ( int ? ) null ,  Id  =  guid  } ) ; dog . Count (). IsEqualTo ( 1 ) ; dog . First (). Age . IsNull () ; dog . First (). Id . IsEqualTo ( guid ) ;
dapper-dot-net Advanced features ,[object Object],connection . Query < int >( @ &quot; select * from    (select 1 as Id union select 2 union select 3) as X    where Id in @Ids &quot; ,   new   {  Ids  =   new   int []   {   1 ,   2 ,   3   } ) ; select   *   from   ( select   1   as   Id   union   select   2   union   all   select   3 )   as  X  where   Id   in   ( @Ids1 ,   @Ids2 ,   @Ids3 )   // @Ids1 = 1 , @Ids2 = 2 , @Ids2 = 3
dapper-dot-net Advanced features ,[object Object],var sql  =  @ &quot; select * from #Posts p    left join #Users u on u.Id = p.OwnerId    Order by p.Id &quot; ; var data  =  connection . Query < Post ,  User ,  Post >( sql ,   ( post ,  user )   =>   {  post . Owner  =  user ;   return  post ;} ) ;   var post  =  data . First () ;   post . Content . IsEqualTo ( &quot; Sams Post1 &quot; ) ;   post . Id . IsEqualTo ( 1 ) ;   post . Owner . Name . IsEqualTo ( &quot; Sam &quot; ) ;   post . Owner . Id . IsEqualTo ( 99 ) ;
dapper-dot-net Advanced features ,[object Object],var sql  =  @ “ select * from Customers where CustomerId = @id  select * from Orders where CustomerId = @id  select * from Returns where CustomerId = @id &quot; ;   using   ( var multi  =  conn . QueryMultiple ( sql ,   new   { id = Id } ))   {   var customer  =  multi . Read < Customer >(). Single () ;   var orders  =  multi . Read < Order >(). ToList () ;   var returns  =  multi . Read < Return >(). ToList () ;     ...   }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],dapper-dot-net Advanced features
Massive Single file database lover ,[object Object],[object Object]
Massive Initializing table // Create a class that wraps a table public   class  Products : DynamicModel  { public  Products (): base ( &quot; northwind &quot; ,   &quot; products &quot; , &quot; productid &quot; )   {} } // or instantiate it inline var tbl  =   new  DynamicModel ( &quot; northwind &quot; ,  tableName : &quot; Products &quot; ,  primaryKeyField : &quot; ProductID &quot; ) ;
Massive Querying var table  =   new  Products () ; var products  =  table . All ( columns :   &quot; ProductName as Name &quot; ,   where :   &quot; WHERE categoryID=@0 &quot; ,   args :   4 ) ; var products  =  table . Find ( CategoryID : 4 , columns : &quot; ProductName &quot; ) // Running ad-hoc queries as needed: var result  =  tbl . Query ( &quot; SELECT * FROM Categories &quot; ) ; var result  =  tbl . Fetch ( &quot; SELECT * FROM Categories &quot; ) ; // Paging var result  =  tbl . Paged ( where :   &quot; UnitPrice > 20 &quot; ,  currentPage : 2 ,  pageSize :   20 ) ;
Massive Updating var table  =   new  Products () ; var poopy  =   new   { ProductName  =   &quot; Chicken Fingers &quot; }; table . Update ( poopy ,   12 ) ; // Works for a form on a web page table . Update ( poopy ,  Request . Form ) ; // Insert var table  =   new  Categories () ; var newID  =  table . Insert ( new   { CategoryName  =   &quot; Buck Fify Stuff &quot; ,  Description  =   &quot; Things I like &quot; } ) ; // Batch updates var table  =   new  Products () ; var drinks  =  table . All ( &quot; WHERE CategoryID = 8 &quot; ) ; // what we get back here is an IEnumerable<ExpandoObject> foreach ( var item  in  drinks ) { item . CategoryID  =   12 ; } table . Save ( drinks ) ;
Massive public   class  Productions  : DynamicModel  { public  Productions ():   base ( &quot; MyConnectionString &quot; , &quot; Productions &quot; , &quot; ID &quot; )   {} public   override   void  Validate ( dynamic item )   { ValidatesPresenceOf ( &quot; Title &quot; ) ; ValidatesNumericalityOf ( item . Price ) ; ValidateIsCurrency ( item . Price ) ; if   ( item . Price  <=   0 ) Errors . Add ( &quot; Price can't be negative &quot; ) ; } } public   class  Customers :  DynamicModel  { public  Customers (): base ( &quot; MyConnectionString &quot; , &quot; Customers &quot; , &quot; ID &quot; )   {} //Add the person to Highrise CRM when they're added to the system... public   override   void  Inserted ( dynamic item )   { //send them to Highrise var svc  =   new  HighRiseApi () ; svc . AddPerson (...) ; } } Changes notification Validation
PetaPoco Tiny ORM to use with non-dynamic POCO objects ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PetaPoco ,[object Object]
Simple.Data an ORM without O, the R or the M &quot;A lightweight, dynamic data access component for .NET&quot;
Simple.Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simple.Data ,[object Object],dynamic  db  =  Database . Open () ; User user  =  db . Users . FindByUserName ( &quot; bob &quot; ) ;   // Method name form user  =  db . Users . FindBy ( UserName :   &quot; bob &quot; ) ;   // Named parameter form @p0   =   'bob' SELECT   *   FROM  Users  WHERE  UserName  =   @p0 IEnumerable < dynamic >  customers  =  db . Customers . FindAll ( db . Customers . CustomerName  ==   &quot; Arthur &quot; ) . OrderByCustomerName () . Distinct () ; @p1   =   'Arthur' select   distinct   dbo . customers . customerid ,  dbo . customers . customer_name from   [ dbo ].[ customers ]   where   [ dbo ].[ customers ].[ customer_name ]   =   @p1   order   by   [ customer_name ] FindAllBy FindBy
Simple.Data ,[object Object],var q  =  db . Employees . Query () . Join ( db . Department ,  Id :  db . Employees . DepartmentId ) . Select ( db . Employees . Name ,  db . Department . Name . As ( &quot; Department &quot; )) ; var q  =  db . Employees . Find ( db . Employees . DepartmentId  ==  db . Department . Id ) . Select ( db . Employees . Name ,  db . Department . Name . As ( &quot; Department &quot; )) ; select   [ dbo ].[ employee ].[ name ], [ dbo ].[ department ].[ name ]   as   [ Department ]   from   [ dbo ].[ employee ] join   [ dbo ].[ department ]   on   ([ dbo ].[ department ].[ id ]   =   [ dbo ].[ employee ].[ departmentid ]) Explicit join Natural join (dynamic form)
Simple.Data ,[object Object],var user  =  db . Users . Insert ( Name :   &quot; Steve &quot; ,  Age :   50 ) ; @p0   =   'Steve' @p1   =   50 insert   into   [ dbo ].[ Users ]   ([ Name ],[ Age ])   values   ( @p0 , @p1 ) var user  =   new  User  {  Name  =   &quot; Steve &quot; ,  Age  =   50   }; db . Users . Insert ( user ) ; By object Named parameters Generated SQL: Insert, Update and Delete methods return a row or rowSet of data that has just been modified.  Insert and Update can be used in two forms, Named parameters and by object. The object can be a POCO or a dynamic.
Simple.Data ,[object Object],db . Users . UpdateById ( Id :   1 ,  Name :   &quot; Steve &quot; ,  Age :   50 ) ; @p0   =   1 ,   @p1   =   'Steve' ,   @p2   =   50 update   [ dbo ].[ Users ]   set   [ Name ]   =   @p1 ,   [ Age ]   =   @p2   where   [ dbo ].[ Users ].[ Id ]   =   @p3 dynamic record  =   new  SimpleRecord () ; record . Id  =   1 ; record . Name  =   &quot; Steve &quot; ; record . Age  =   50 ; db . Users . UpdateById ( record ) ;  // Method name form db . Users . Update ( record ) ;  // By Primary Key By object (can be POCO or dynamic) Named parameters Generated SQL:
Simple.Data ,[object Object],db . Users . UpdateAll ( Name :   &quot; Steve &quot; ) ; @p0   =   'Steve' update   [ dbo ].[ Users ]   set   [ Name ]   =   @p Named parameters db . Users . UpdateAll ( Name :   &quot; Steve &quot; ,  Condition :  db . Users . Age  >   30 ) ; db . Users . UpdateAll ( db . Users . Age  >   30 ,  Name :   &quot; Steve &quot; ) ; With expression @p0   =   'Steve' @p1   =   30 update   [ dbo ].[ Users ]   set   [ Name ]   =   @p0   where   [ dbo ].[ Users ].[ Age ]   >   @p1
Simple.Data ,[object Object],db . Users . Delete ( Id :   1 ) ; Named parameters db . Users . DeleteById ( Id :   1 ) ; db . Users . DeleteAll ( db . Users . Age  >   42  && db . Users . Name . Like ( &quot; J% &quot; )) ; Method name form  db . Users . DeleteAll () ; With expression With no Where clause
Simple.Data ,[object Object],Used in two production systems. First one is CQRS based and Simple.Data is used to actualize “Read Model” there. Within the second one, Simple.Data is used to store normalized data which we receive from third party in XML form. In both systems Simple.Data is used for integration tests. It just amazing how  simpler  design can be when you don’t need data classes just to map them to database tables.
Simple.Data ,[object Object]
TL;DR What I liked in Micro ORMs Usually leads to  better performance . Though, that was not a key feature for me.  Write less, do more  – instead of writing infrastructural code (Session management, Repositories, Specifications, Mappings etc.) you concentrated on getting things done…. things which business needs, not technical issues dictated by our infrastructure. With less features in Micro ORMs you are forced to design things simpler – simpler object hierarchies, simpler database schema. And you are forced to apply good patterns. Separating Reads and Writes is a good example. That all leads to a better design .
References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Follow Friday ,[object Object],[object Object],[object Object],[object Object],[object Object]
 

More Related Content

What's hot

SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.fRui Apps
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...Marco Gralike
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2RORLAB
 
Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Davide Rossi
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code LabColin Su
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesMarco Gralike
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4DEVCON
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4DEVCON
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180Mahmoud Samir Fayed
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseMarco Gralike
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)dineshrana201992
 

What's hot (20)

SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2
 
GORM
GORMGORM
GORM
 
Dartprogramming
DartprogrammingDartprogramming
Dartprogramming
 
Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Grails: a quick tutorial (1)
Grails: a quick tutorial (1)
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
 
Lab final
Lab finalLab final
Lab final
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
ORM in Django
ORM in DjangoORM in Django
ORM in Django
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory Database
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
 

Similar to Micro-ORM Introduction - Don't overcomplicate

Lewis Chiu Portfolio
Lewis Chiu PortfolioLewis Chiu Portfolio
Lewis Chiu PortfolioLewisChiu
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardJAX London
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitPeter Wilcsinszky
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)MongoDB
 
Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009Core Software Group
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedMarcinStachniuk
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails Mohit Jain
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceMaarten Balliauw
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008maximgrp
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and DashboardsAtlassian
 

Similar to Micro-ORM Introduction - Don't overcomplicate (20)

Lewis Chiu Portfolio
Lewis Chiu PortfolioLewis Chiu Portfolio
Lewis Chiu Portfolio
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
PostThis
PostThisPostThis
PostThis
 
What's New in ZF 1.10
What's New in ZF 1.10What's New in ZF 1.10
What's New in ZF 1.10
 
Sencha Touch Intro
Sencha Touch IntroSencha Touch Intro
Sencha Touch Intro
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
 
Linq intro
Linq introLinq intro
Linq intro
 
jdbc
jdbcjdbc
jdbc
 
Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009
 
Framework
FrameworkFramework
Framework
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
 

More from Kiev ALT.NET

Design by Contract
Design by ContractDesign by Contract
Design by ContractKiev ALT.NET
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive ExtensionsKiev ALT.NET
 
Continuous Integration (CI)
Continuous Integration (CI)Continuous Integration (CI)
Continuous Integration (CI)Kiev ALT.NET
 
WebSharper - веб-программирование без слёз
WebSharper - веб-программирование без слёзWebSharper - веб-программирование без слёз
WebSharper - веб-программирование без слёзKiev ALT.NET
 
F# - функциональный язык «новой» волны
F# - функциональный  язык «новой» волныF# - функциональный  язык «новой» волны
F# - функциональный язык «новой» волныKiev ALT.NET
 
Caliburn Micro Overview
Caliburn Micro OverviewCaliburn Micro Overview
Caliburn Micro OverviewKiev ALT.NET
 
Введение в MVVM
Введение в MVVMВведение в MVVM
Введение в MVVMKiev ALT.NET
 
Command-Query Responsibility Segregation: теория и практика
Command-Query Responsibility Segregation: теория и практикаCommand-Query Responsibility Segregation: теория и практика
Command-Query Responsibility Segregation: теория и практикаKiev ALT.NET
 

More from Kiev ALT.NET (16)

CQRS EventStore
CQRS EventStoreCQRS EventStore
CQRS EventStore
 
Design by Contract
Design by ContractDesign by Contract
Design by Contract
 
Async
AsyncAsync
Async
 
Linq providers
Linq providersLinq providers
Linq providers
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive Extensions
 
NoSql, MongoDb
NoSql, MongoDbNoSql, MongoDb
NoSql, MongoDb
 
CouchDb
CouchDbCouchDb
CouchDb
 
Orchard
OrchardOrchard
Orchard
 
Mercurial
MercurialMercurial
Mercurial
 
CI via TFS
CI via TFSCI via TFS
CI via TFS
 
Continuous Integration (CI)
Continuous Integration (CI)Continuous Integration (CI)
Continuous Integration (CI)
 
WebSharper - веб-программирование без слёз
WebSharper - веб-программирование без слёзWebSharper - веб-программирование без слёз
WebSharper - веб-программирование без слёз
 
F# - функциональный язык «новой» волны
F# - функциональный  язык «новой» волныF# - функциональный  язык «новой» волны
F# - функциональный язык «новой» волны
 
Caliburn Micro Overview
Caliburn Micro OverviewCaliburn Micro Overview
Caliburn Micro Overview
 
Введение в MVVM
Введение в MVVMВведение в MVVM
Введение в MVVM
 
Command-Query Responsibility Segregation: теория и практика
Command-Query Responsibility Segregation: теория и практикаCommand-Query Responsibility Segregation: теория и практика
Command-Query Responsibility Segregation: теория и практика
 

Recently uploaded

Old Age but fruitful and meaningful.pptx
Old Age but fruitful and meaningful.pptxOld Age but fruitful and meaningful.pptx
Old Age but fruitful and meaningful.pptxInnovator Marbun
 
Free eBook ~Short Inspirational Stories - The Benefits.pdf
Free eBook ~Short Inspirational Stories - The Benefits.pdfFree eBook ~Short Inspirational Stories - The Benefits.pdf
Free eBook ~Short Inspirational Stories - The Benefits.pdfOH TEIK BIN
 
SERPENT COIL: THE AWAKENING OF KUNDALINI
SERPENT COIL: THE AWAKENING OF KUNDALINISERPENT COIL: THE AWAKENING OF KUNDALINI
SERPENT COIL: THE AWAKENING OF KUNDALINISantanu Das
 
Easter Apocalypse_Palm Sunday_Rev. 7.pptx
Easter Apocalypse_Palm Sunday_Rev. 7.pptxEaster Apocalypse_Palm Sunday_Rev. 7.pptx
Easter Apocalypse_Palm Sunday_Rev. 7.pptxStephen Palm
 
All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...
All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...
All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...iqra tube
 
Indications of Rebirth ~ My Reflections (English & Chinese).pptx
Indications of  Rebirth ~ My Reflections (English & Chinese).pptxIndications of  Rebirth ~ My Reflections (English & Chinese).pptx
Indications of Rebirth ~ My Reflections (English & Chinese).pptxOH TEIK BIN
 
DP & Jesus Marriage - 2 potential candidates
DP & Jesus Marriage - 2 potential candidatesDP & Jesus Marriage - 2 potential candidates
DP & Jesus Marriage - 2 potential candidatesBengt & Maarit de Paulis
 
April 2024 Calendar of Events Hope Lutheran Church Floodwood
April 2024 Calendar of Events Hope Lutheran Church FloodwoodApril 2024 Calendar of Events Hope Lutheran Church Floodwood
April 2024 Calendar of Events Hope Lutheran Church FloodwoodFloodwoodvern
 
365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...
365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...
365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...Eizijesu Obahaiye
 
The_Chronological_Life_of_Christ_Part_93_Fear God
The_Chronological_Life_of_Christ_Part_93_Fear GodThe_Chronological_Life_of_Christ_Part_93_Fear God
The_Chronological_Life_of_Christ_Part_93_Fear GodNetwork Bible Fellowship
 
DP & Nostradamus-Fatima-Bailey-Branham-Ford - Short vers
DP & Nostradamus-Fatima-Bailey-Branham-Ford - Short versDP & Nostradamus-Fatima-Bailey-Branham-Ford - Short vers
DP & Nostradamus-Fatima-Bailey-Branham-Ford - Short versBengt & Maarit de Paulis
 
The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...
The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...
The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...Cometan
 
Deerfoot Church of Christ Bulletin 3 24 24
Deerfoot Church of Christ Bulletin 3 24 24Deerfoot Church of Christ Bulletin 3 24 24
Deerfoot Church of Christ Bulletin 3 24 24deerfootcoc
 
Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]
Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]
Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]iqra tube
 

Recently uploaded (15)

Old Age but fruitful and meaningful.pptx
Old Age but fruitful and meaningful.pptxOld Age but fruitful and meaningful.pptx
Old Age but fruitful and meaningful.pptx
 
Free eBook ~Short Inspirational Stories - The Benefits.pdf
Free eBook ~Short Inspirational Stories - The Benefits.pdfFree eBook ~Short Inspirational Stories - The Benefits.pdf
Free eBook ~Short Inspirational Stories - The Benefits.pdf
 
SERPENT COIL: THE AWAKENING OF KUNDALINI
SERPENT COIL: THE AWAKENING OF KUNDALINISERPENT COIL: THE AWAKENING OF KUNDALINI
SERPENT COIL: THE AWAKENING OF KUNDALINI
 
Easter Apocalypse_Palm Sunday_Rev. 7.pptx
Easter Apocalypse_Palm Sunday_Rev. 7.pptxEaster Apocalypse_Palm Sunday_Rev. 7.pptx
Easter Apocalypse_Palm Sunday_Rev. 7.pptx
 
English - The 1st Book of Adam and Eve.pdf
English - The 1st Book of Adam and Eve.pdfEnglish - The 1st Book of Adam and Eve.pdf
English - The 1st Book of Adam and Eve.pdf
 
All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...
All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...
All About Zakah for Muslim Americans - Dr. Main Alqudah [https://www.guidance...
 
Indications of Rebirth ~ My Reflections (English & Chinese).pptx
Indications of  Rebirth ~ My Reflections (English & Chinese).pptxIndications of  Rebirth ~ My Reflections (English & Chinese).pptx
Indications of Rebirth ~ My Reflections (English & Chinese).pptx
 
DP & Jesus Marriage - 2 potential candidates
DP & Jesus Marriage - 2 potential candidatesDP & Jesus Marriage - 2 potential candidates
DP & Jesus Marriage - 2 potential candidates
 
April 2024 Calendar of Events Hope Lutheran Church Floodwood
April 2024 Calendar of Events Hope Lutheran Church FloodwoodApril 2024 Calendar of Events Hope Lutheran Church Floodwood
April 2024 Calendar of Events Hope Lutheran Church Floodwood
 
365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...
365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...
365 Days of Thanking God_ Cultivating a Heart of Thanksgiving Everyday (Revis...
 
The_Chronological_Life_of_Christ_Part_93_Fear God
The_Chronological_Life_of_Christ_Part_93_Fear GodThe_Chronological_Life_of_Christ_Part_93_Fear God
The_Chronological_Life_of_Christ_Part_93_Fear God
 
DP & Nostradamus-Fatima-Bailey-Branham-Ford - Short vers
DP & Nostradamus-Fatima-Bailey-Branham-Ford - Short versDP & Nostradamus-Fatima-Bailey-Branham-Ford - Short vers
DP & Nostradamus-Fatima-Bailey-Branham-Ford - Short vers
 
The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...
The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...
The Mormon & Quaker Moons of Lancashire: Stories of Religious Conversion & Mi...
 
Deerfoot Church of Christ Bulletin 3 24 24
Deerfoot Church of Christ Bulletin 3 24 24Deerfoot Church of Christ Bulletin 3 24 24
Deerfoot Church of Christ Bulletin 3 24 24
 
Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]
Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]
Islamic Finance 101 - Dr. Main Alqudah [https://www.guidancecollege.org/]
 

Micro-ORM Introduction - Don't overcomplicate

  • 1. Don't overcomplicate Introduction to Micro ORM Ivan Korneliuk @korneliuk http://korneliuk.blogspot.com/ 31337 Kiev ALT.NET
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. dapper-dot-net Querying POCOs public class Dog { public int ? Age { get ; set ; } public Guid Id { get ; set ; } public string Name { get ; set ; } public float ? Weight { get ; set ; } public int IgnoredProperty { get { return 1 ; } } } var guid = Guid . NewGuid () ; var dog = connection . Query < Dog >( &quot; select Age = @Age, Id = @Id &quot; , new { Age = ( int ? ) null , Id = guid } ) ; dog . Count (). IsEqualTo ( 1 ) ; dog . First (). Age . IsNull () ; dog . First (). Id . IsEqualTo ( guid ) ;
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. Massive Initializing table // Create a class that wraps a table public class Products : DynamicModel { public Products (): base ( &quot; northwind &quot; , &quot; products &quot; , &quot; productid &quot; ) {} } // or instantiate it inline var tbl = new DynamicModel ( &quot; northwind &quot; , tableName : &quot; Products &quot; , primaryKeyField : &quot; ProductID &quot; ) ;
  • 13. Massive Querying var table = new Products () ; var products = table . All ( columns : &quot; ProductName as Name &quot; , where : &quot; WHERE categoryID=@0 &quot; , args : 4 ) ; var products = table . Find ( CategoryID : 4 , columns : &quot; ProductName &quot; ) // Running ad-hoc queries as needed: var result = tbl . Query ( &quot; SELECT * FROM Categories &quot; ) ; var result = tbl . Fetch ( &quot; SELECT * FROM Categories &quot; ) ; // Paging var result = tbl . Paged ( where : &quot; UnitPrice > 20 &quot; , currentPage : 2 , pageSize : 20 ) ;
  • 14. Massive Updating var table = new Products () ; var poopy = new { ProductName = &quot; Chicken Fingers &quot; }; table . Update ( poopy , 12 ) ; // Works for a form on a web page table . Update ( poopy , Request . Form ) ; // Insert var table = new Categories () ; var newID = table . Insert ( new { CategoryName = &quot; Buck Fify Stuff &quot; , Description = &quot; Things I like &quot; } ) ; // Batch updates var table = new Products () ; var drinks = table . All ( &quot; WHERE CategoryID = 8 &quot; ) ; // what we get back here is an IEnumerable<ExpandoObject> foreach ( var item in drinks ) { item . CategoryID = 12 ; } table . Save ( drinks ) ;
  • 15. Massive public class Productions : DynamicModel { public Productions (): base ( &quot; MyConnectionString &quot; , &quot; Productions &quot; , &quot; ID &quot; ) {} public override void Validate ( dynamic item ) { ValidatesPresenceOf ( &quot; Title &quot; ) ; ValidatesNumericalityOf ( item . Price ) ; ValidateIsCurrency ( item . Price ) ; if ( item . Price <= 0 ) Errors . Add ( &quot; Price can't be negative &quot; ) ; } } public class Customers : DynamicModel { public Customers (): base ( &quot; MyConnectionString &quot; , &quot; Customers &quot; , &quot; ID &quot; ) {} //Add the person to Highrise CRM when they're added to the system... public override void Inserted ( dynamic item ) { //send them to Highrise var svc = new HighRiseApi () ; svc . AddPerson (...) ; } } Changes notification Validation
  • 16.
  • 17.
  • 18. Simple.Data an ORM without O, the R or the M &quot;A lightweight, dynamic data access component for .NET&quot;
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. TL;DR What I liked in Micro ORMs Usually leads to better performance . Though, that was not a key feature for me. Write less, do more – instead of writing infrastructural code (Session management, Repositories, Specifications, Mappings etc.) you concentrated on getting things done…. things which business needs, not technical issues dictated by our infrastructure. With less features in Micro ORMs you are forced to design things simpler – simpler object hierarchies, simpler database schema. And you are forced to apply good patterns. Separating Reads and Writes is a good example. That all leads to a better design .
  • 29.
  • 30.
  • 31.
  • 32.