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 >( " select Age = @Age, Id = @Id " , 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 ( " northwind " , " products " , " productid " ) {} } // or instantiate it inline var tbl = new DynamicModel ( " northwind " , tableName : " Products " , primaryKeyField : " ProductID " ) ;
13. Massive Querying var table = new Products () ; var products = table . All ( columns : " ProductName as Name " , where : " WHERE categoryID=@0 " , args : 4 ) ; var products = table . Find ( CategoryID : 4 , columns : " ProductName " ) // Running ad-hoc queries as needed: var result = tbl . Query ( " SELECT * FROM Categories " ) ; var result = tbl . Fetch ( " SELECT * FROM Categories " ) ; // Paging var result = tbl . Paged ( where : " UnitPrice > 20 " , currentPage : 2 , pageSize : 20 ) ;
14. Massive Updating var table = new Products () ; var poopy = new { ProductName = " Chicken Fingers " }; 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 = " Buck Fify Stuff " , Description = " Things I like " } ) ; // Batch updates var table = new Products () ; var drinks = table . All ( " WHERE CategoryID = 8 " ) ; // 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 ( " MyConnectionString " , " Productions " , " ID " ) {} public override void Validate ( dynamic item ) { ValidatesPresenceOf ( " Title " ) ; ValidatesNumericalityOf ( item . Price ) ; ValidateIsCurrency ( item . Price ) ; if ( item . Price <= 0 ) Errors . Add ( " Price can't be negative " ) ; } } public class Customers : DynamicModel { public Customers (): base ( " MyConnectionString " , " Customers " , " ID " ) {} //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 "A lightweight, dynamic data access component for .NET"
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 .