SlideShare a Scribd company logo
Simple.Data
… an ORM without O, R or M
Timothée Bourguignon
1
What is Simple.Data?

An O/RM without O, R or M!

3
Hands-on!
• SQL Server + MvcMusicStore DB

– http://mvcmusicstore.codeplex.com/

4
What is Simple.Data?
• Lightweight way of manipulating data
– Based on .NET 4.0's „dynamic“ keyword
– Interprets method and property names
– Maps them to your underlying data-store
– Prevents SQL Injection
– Inspired by Ruby’s ActiveRecord and DataMappers
– Open Source & runs on Mono
– V1.0 rc3 released in Nov. 2012

5
The Menu
•
•
•
•
•
•
•
•

Generalities
Conventions
CRUD Operations
Objects Returned
Joins & Evaluation Strategies
Various Functions
Tool & Testing
Wrap-Up

• Hands-ons
along the
way

6
Database agnostic

7
Package Architecture
Core

MongoDB

OData

Azure

Ado

SqlServer
SqlCompact40
Oracle
VistaDB
MySQL
SQLite
PostgreSQL
SQLAnywhere
Informix
Mocking

9
Nuget Packages

PM> Install-Package
Simple.Data.SqlServer
Simple.Data.Ado
Simple.Data.SqlCompact40
Simple.Data.Sqlite
Simple.Data.MongoDB
...

10
Conventions

11
Opening a Connection
var magicDb = Database
.OpenConnection("ConnectString");
var fileDb = Database
.OpenConnection("MyDB.sdf");

• Per default connections are aggressively
opened and closed for each query
• Supports shared connections
12
Choose your weapon
• The „Fluid“ Way
– Methods & properties convention-based mapping

• The „Indexer“ Way
– Identification via an indexer syntax

13
The Fluid Way

Co
lu
m
Pa
n
ra
m
et
er
s

an
d
m
Co
m

Ta
bl
e/
Vi
ew

db.album.FindAllByGenreId(3);

14
The Indexer Way
• The problem
//Find by „Candy“ or find by „C and Y“?
db.sweets.FindAllByCAndY("Oreo");

• The solution
//Full indexer way
db["sweets"].FindAllBy(Candy: "Oreo");
//Hybrid fluid + indexer
db.sweets.FindAllBy(Candy: "Oreo");
db["city"].FindAllByCityName("Paris");

15
Target Matching
• Sequence
– Exact match
– Case-insensitive - non-alphanumeric chars
– Pluralized/Singularized version

• The following are thus all identical
– Albums.GenreId
– Album.GenreId
– ALBUMS.GENREID
– ALBUM.GENREID
– [ALBUMS].[GENREID]

– [ALBUM].[GENREID]
– AlBuM.geNReId
– Al__*bum.Genr-eId
– ...
16
No IntelliSence

•
•
•
•

Dynamics => no member / function inferrence
Schema analyse planned for Simple.Data v2
Tool: Simple.Data.Pad
Still easy to get used to
17
CRUD OPERATIONS

18
Create
• Insert(object or named parameters)

19
Read
• Read
– All()
– Find(simple expressions)
– Get(primary key)
– FindAll(optional condition)
– FindAllByXXX(parameter)

20
Update
• Update(object or named parameters)
– Update
– UpdateByXXX
– UpdateAll + optional condition

• Upsert e.g. Update or Insert
• Some kind of optimistic locking
– Update(modifiedObject, originalObject)
– Fails if the column(s) you are modifying changed
• Nota: does not work with Upsert
21
Delete
• Delete
– Delete(object or named parameters)
– DeleteByXXX(parameters)
– DeleteAll(optional conditions)

22
Hands-on!
• CRUD Operations
– Insert
– Update
– Delete
– Read

23
Objects Returned

24
SimpleRecord
• Dynamic object
• Contains a property for each of the columns
requested whose values are those of the
single row retrieved from the data store
• „Cast-able“ to a concrete implementation

25
SimpleQuery
•
•
•
•

Dynamic object
Similar to LINQ structure
Executes when enumerated
Contains a SimpleRecord object for each row
returned

26
Casting
• Casting to objects
– Implicit
– Explicit: Cast<T>, ToList, ToList<T>, ToArray,
ToArray<T>

• Hands-On
– Implicit casting
– Explicit casting
27
Joins
& Evaluation Strategies

28
Hands-on!
• Lazy natural evaluation
• Casting + Lazy?
• Eager evaluation

29
Joins
• Lazy loading
– Natural Joins / Table chaining

• Eager Loading
– „With Joins“
• With/WithXXX
• WithOne
• WithMany

Foreign-Key relationship present
No Foreign-Key relationship necessary
(no referential integrity)

– „Explicit Joins“
• Join
• LeftJoin
• OuterJoin

Natural joins can be used as part of an explicit
join, the join is then eager loaded
30
Hands-on!
• Eager Joins
– Select + Natural Joins + As
– With

31
Various Functions

32
Ordering Results
• OrderBy, OrderByDescending
• ThenBy, ThenByDescending
db.Albums.All().OrderByGenreId()
.ThenByArtistIdDescending();

33
Scalar Queries
•
•
•
•

GetCount
GetCountBy
Exists, Any
ExistsBy, AnyBy

int albumCount = db.Albums.GetCount(
db.Albums.GenreId == 2);

34
Query Modifiers
• Select
– Star & AllColumns
db.Albums.All().Select(db.Albums.Title,
db.Albums.ArtistId);

35
Query Modifiers
• Column Aliasing: As(string)
var albums = db.Albums.All().Select(
db.Albums.AlbumId,
db.Albums.Title.As("AlbumName"));

36
Query Modifiers
• Where clauses
– Operators (+, -, *, /, %)
– IN, BETWEEN, LIKE, IS NULL
var albums = db.Albums.FindAllByGenreId(1)
.Select(db.Albums.Title)
.Where(db.Albums.Price < 8);
db.Albums.All().Where(
db.Albums.Title.Like("%Side Of The%"));

37
Aggregate Functions
• Grouping and Aggregates
– Having → Group By / Having
– Min, Max, Avg, Sum
var cheapAlbums = db.Albums.All()
.Having(db.Albums.Price < 9).ToList();
var totalCost = db.Albums.All().Select(
db.Albums.Price.Sum().As("TotalCost"));

38
Stored Procedures
• Like a function...
CREATE PROCEDURE ProcedureWithParameters
@One VARCHAR(MAX),
@Two VARCHAR(MAX)
AS
SELECT * FROM Customers
WHERE Firstname = @One and Lastname like @Two
db.ProcedureWithParameters(1, 2);

39
Transactions
• Wrap up the calls
using (var transaction = db.BeginTransaction())
{
transaction.albums.Insert(GenreId: 1...);
transaction.Commit();
}

40
Tool & Testing

41
Tool: Simple.Data.Pad
• Similar to LINQ-Pad... kind of...
– https://github.com/markrendle/Simple.Data.Pad

42
Testing: InMemoryAdapter
[Test]
public void Should_do_something()
{
var adapter = new InMemoryAdapter();
Database.UseMockAdapter(adapter);
var db = Database.Open();
db.Test.Insert(Id: 1, Name: "Alice");
//...
}

• The InMemoryAdapter supports
– Joins, Transactions, Stored procedures...
43
InMemoryAdapter Configuration
• Tweaking functions
– SetKeyColumn
– SetAutoIncrementColumn
– AddFunction (stored procedure)
– ConfigureJoin
– ...

44
Design

45
Wrap-Up

46
Wrap-up
• OpenSource, Mono
• Everything is
dynamic
• Fluid-, Indexer Way
• CRUD
– FindXXX, DeleteXXX,
UpdateXXX etc.

• Dynamics Objects
Returned

• Joins, lazy, eager
– Natural, WithXXX,
Join

• Various Functions
– Group, Order, Scalar,
Modifiers etc.

• Tool & Testing
• Design

47
Simple.Data in Short
•
•
•
•
•

Lightweight
Readable
Compelling
Fun to use
Interesing design

• Dynamics extensive
testing
• Good understanding
upfront

• My Recommendation
– Try it and study it
– Take it for a spin for some tooling and/or
prototyping
– ...and some projects?
48
Further Reading
• Github

– https://github.com/markrendle/Simple.Data

• Nuget

– http://nuget.org/packages?q=simple.data

• GoogleGroup

– https://groups.google.com/forum/?fromgroups#!
forum/simpledata

• Mark Rendle

– @MarkRendle
– http://blog.markrendle.net/
49
Ich freue mich auf Eure Fragen!
tim.bourguignon@mathema.de
about.me/timbourguignon

50

More Related Content

PPSX
Collections - Lists, Sets
Hitesh-Java
 
PPT
Groovy unleashed
Isuru Samaraweera
 
PDF
Collections Framework Begineers guide 2
Kenji HASUNUMA
 
PDF
Using JSON with MariaDB and MySQL
Anders Karlsson
 
KEY
Haskell for Scala-ists
chriseidhof
 
PPTX
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
Speedment, Inc.
 
PDF
Hackersnl
chriseidhof
 
PPTX
Collections - Lists & sets
RatnaJava
 
Collections - Lists, Sets
Hitesh-Java
 
Groovy unleashed
Isuru Samaraweera
 
Collections Framework Begineers guide 2
Kenji HASUNUMA
 
Using JSON with MariaDB and MySQL
Anders Karlsson
 
Haskell for Scala-ists
chriseidhof
 
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
Speedment, Inc.
 
Hackersnl
chriseidhof
 
Collections - Lists & sets
RatnaJava
 

What's hot (20)

PPTX
Eurydike: Schemaless Object Relational SQL Mapper
ESUG
 
PDF
Java Collection framework
ankitgarg_er
 
PDF
Spark Schema For Free with David Szakallas
Databricks
 
PPTX
BGOUG15: JSON support in MySQL 5.7
Georgi Kodinov
 
PPTX
Collections Array list
RatnaJava
 
PDF
Introduction to meta-programming in scala
Alessandro Marrella
 
PDF
Java Collections API
Alex Miller
 
PPTX
SPL - The Undiscovered Library - PHPBarcelona 2015
Mark Baker
 
PDF
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
Databricks
 
PDF
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan Shevchenko
 
PDF
Collections In Java
Binoj T E
 
PDF
Spark schema for free with David Szakallas
Databricks
 
PPTX
Java - Collections framework
Riccardo Cardin
 
KEY
Metaprogramming in Haskell
Hiromi Ishii
 
PPTX
Java 103 intro to java data structures
agorolabs
 
KEY
ぐだ生 Java入門第一回(equals hash code_tostring)
Makoto Yamazaki
 
PPTX
Object Class
RatnaJava
 
PPTX
.Net Collection Classes Deep Dive - Rocksolid Tour 2013
Gary Short
 
PPTX
An introduction to scala
Xing
 
Eurydike: Schemaless Object Relational SQL Mapper
ESUG
 
Java Collection framework
ankitgarg_er
 
Spark Schema For Free with David Szakallas
Databricks
 
BGOUG15: JSON support in MySQL 5.7
Georgi Kodinov
 
Collections Array list
RatnaJava
 
Introduction to meta-programming in scala
Alessandro Marrella
 
Java Collections API
Alex Miller
 
SPL - The Undiscovered Library - PHPBarcelona 2015
Mark Baker
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
Databricks
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan Shevchenko
 
Collections In Java
Binoj T E
 
Spark schema for free with David Szakallas
Databricks
 
Java - Collections framework
Riccardo Cardin
 
Metaprogramming in Haskell
Hiromi Ishii
 
Java 103 intro to java data structures
agorolabs
 
ぐだ生 Java入門第一回(equals hash code_tostring)
Makoto Yamazaki
 
Object Class
RatnaJava
 
.Net Collection Classes Deep Dive - Rocksolid Tour 2013
Gary Short
 
An introduction to scala
Xing
 
Ad

Viewers also liked (20)

PDF
OO Design
Alex Fedorov
 
PDF
C# Dynamics in the Wild
Tim Bourguignon
 
PDF
Refactoring the Tennis Kata v2 (2016)
Peter Kofler
 
PPTX
Angular JS deep dive
Axilis
 
PPTX
Micro ORM vs Entity Framework
Axilis
 
PDF
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
 
PDF
Modeling Microservices
Sander Hoogendoorn
 
PDF
Java Libraries You Can’t Afford to Miss
Andres Almiray
 
PDF
Cristian frasinaru curs practic de java
Corniciuc Oana
 
DOC
Acatistul Sf. Nicolae
Alin Cazacu
 
PPTX
History Design_ Surrealism
Universiti Pendidikan Sultan Idris
 
PPT
Geeli all(2)
Apoorva
 
PPT
Lxsykj
880205
 
PDF
List posts: Why people love and hate Lists. Curation Tips for List Makers
Nick Kellet
 
PDF
TEXOCT2015
Textile Forum
 
PPS
Uganda Martyrs University
Abraham Kule
 
PPT
Geografía
Shunichi Watanabe
 
PPTX
Finding Singapore Cases and Legislation
isc_library
 
PDF
Hướng dẫn cài đặt và crack Vijeo Designer 6
locbachkhoa
 
PDF
Cap1 limites e continuidade
Maria De Fátima Malta
 
OO Design
Alex Fedorov
 
C# Dynamics in the Wild
Tim Bourguignon
 
Refactoring the Tennis Kata v2 (2016)
Peter Kofler
 
Angular JS deep dive
Axilis
 
Micro ORM vs Entity Framework
Axilis
 
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
 
Modeling Microservices
Sander Hoogendoorn
 
Java Libraries You Can’t Afford to Miss
Andres Almiray
 
Cristian frasinaru curs practic de java
Corniciuc Oana
 
Acatistul Sf. Nicolae
Alin Cazacu
 
History Design_ Surrealism
Universiti Pendidikan Sultan Idris
 
Geeli all(2)
Apoorva
 
Lxsykj
880205
 
List posts: Why people love and hate Lists. Curation Tips for List Makers
Nick Kellet
 
TEXOCT2015
Textile Forum
 
Uganda Martyrs University
Abraham Kule
 
Geografía
Shunichi Watanabe
 
Finding Singapore Cases and Legislation
isc_library
 
Hướng dẫn cài đặt và crack Vijeo Designer 6
locbachkhoa
 
Cap1 limites e continuidade
Maria De Fátima Malta
 
Ad

Similar to Introduction to Simple.Data (20)

PPSX
Seesion 7 ASP.Net (MVC) Model
Mustafa Saeed
 
PPT
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
 
PDF
10.Local Database & LINQ
Nguyen Tuan
 
PPT
Object Relational Mapping with LINQ To SQL
Shahriar Hyder
 
PPTX
In memory databases presentation
Michael Keane
 
PDF
Hybrid Databases - PHP UK Conference 22 February 2019
Dave Stokes
 
PPTX
Dev-In-Town:Linq To Sql by Chan Ming Man
Quek Lilian
 
PPTX
Windows Phone 8 - 7 Local Database
Oliver Scheer
 
PPTX
Linq to sql
Muhammad Younis
 
PPTX
Linqtosql 090629035715 Phpapp01
google
 
PDF
Whos afraid of front end databases?
Gil Fink
 
PDF
Querier – simple relational database access
ESUG
 
PPTX
Simple.Data intro slides
Mark Rendle
 
PPTX
ORM - Ivan Marković
Software StartUp Academy Osijek
 
PDF
Who's afraid of front end databases?
Gil Fink
 
PDF
ORM Pink Unicorns
Ortus Solutions, Corp
 
PPTX
Freeing Yourself from an RDBMS Architecture
David Hoerster
 
PPT
LINQ-Introduction.ppt
ssusera8c91a
 
PDF
Killing Shark-Riding Dinosaurs with ORM
Ortus Solutions, Corp
 
PPTX
Introduction to FluentData - The Micro ORM
Lars-Erik Kindblad
 
Seesion 7 ASP.Net (MVC) Model
Mustafa Saeed
 
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
 
10.Local Database & LINQ
Nguyen Tuan
 
Object Relational Mapping with LINQ To SQL
Shahriar Hyder
 
In memory databases presentation
Michael Keane
 
Hybrid Databases - PHP UK Conference 22 February 2019
Dave Stokes
 
Dev-In-Town:Linq To Sql by Chan Ming Man
Quek Lilian
 
Windows Phone 8 - 7 Local Database
Oliver Scheer
 
Linq to sql
Muhammad Younis
 
Linqtosql 090629035715 Phpapp01
google
 
Whos afraid of front end databases?
Gil Fink
 
Querier – simple relational database access
ESUG
 
Simple.Data intro slides
Mark Rendle
 
ORM - Ivan Marković
Software StartUp Academy Osijek
 
Who's afraid of front end databases?
Gil Fink
 
ORM Pink Unicorns
Ortus Solutions, Corp
 
Freeing Yourself from an RDBMS Architecture
David Hoerster
 
LINQ-Introduction.ppt
ssusera8c91a
 
Killing Shark-Riding Dinosaurs with ORM
Ortus Solutions, Corp
 
Introduction to FluentData - The Micro ORM
Lars-Erik Kindblad
 

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
The Future of Artificial Intelligence (AI)
Mukul
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 

Introduction to Simple.Data