SlideShare a Scribd company logo
ASPNET CORE DATA ACCESS
ENTITY FRAMEWORK CORE & MICRO ORMS
ETAT DES LIEUX : EF CORE 1.0
 Nouvelles plateformes
 .NET CORE (ASP.NET Core, UWP)
 .NET Framework (ASP.NET, WPF, Windows Forms)
 XAMARIN
 Windows Phone
 Windows Store
 MAC
 Linux
ETAT DES LIEUX : EF CORE 1.0
 Nouvelles sources de données
 Relationnelles (SQL Server, SQL Lite, SQL Compact, Postgres, MySQL, Oracle)
 Non relationnelles (Redis, Azure Table Storage)
 InMemory (à utiliser pour les test)
 Providers disponibles uniquement pour les SGBD relationnels pour la v 1.0
 Possibilité de créer son propre provider
ENTITY FRAMEWORK CORE 1.0
 On repart de Zero mais on garde le meilleur
 Code First
 Code First from Database
 Approche totalement modulaire
 IOC friendly
 Totalement Open source comme tout ce qui finit par Core… donc code source disponible sur
GitHub et possiblité de contribuer son l’évolution.
 EF Core n’est pas production ready
ENTITY FRAMEWORK CORE 1.0
 Fonctionnalités legacy
 Change tracking
 Migrations
 DbContext API
 Linq to Entities
 SaveChanges
 Fonctionnalités supprimées
 EDMX
 Entity SQL
 Complex Mapping
 Migrations automatiques
ENTITY FRAMEWORK CORE 1.0
 Nouvelles fonctionnalités
 Dependency injection
 Lancer des Batch avec CUD
 Créer des clé étrangères
 SQL généré plus propre et plus light
 Amélioration des graphes d’objets déconnectés
 Fonctionnalités à venir
 Mapping des procédures stockées
 Lazy loading
ENTITY FRAMEWORK CORE 1.0.1
DEMARRAGE
ENTITY FRAMEWORK CORE 1.0
 Package à installer
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1 "
 Création d’un DbContext
public class CookBookContext : DbContext
{
public CookBookContext(DbContextOptions<CookBookContext> options) : base(options) { }
public DbSet<Book> Book { get; set; }
public DbSet<Recipe> Recipe { get; set; }
}
ENTITY FRAMEWORK CORE 1.0
 Config dans appsettings.json
{
"ConnectionStrings": {
"DbConnection": "Data Source=mcnltp173;Initial Catalog=CookBook;Integrated Security=True"
}
}
 Config dans Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<CookBookContext>(
options => options.UseSqlServer(Configuration.GetConnectionString("DbConnection")));
}
ENTITY FRAMEWORK CORE 1.0
 Utilisation
public class HomeController : Controller
{
private readonly CookBookContext _context;
public HomeController(CookBookContext context)
{
_context = context;
}
public IActionResult Index()
{
var books = _context.Book.ToList();
return View(books);
}
}
ENTITY FRAMEWORK CORE 1.0.1
REVERSE ENGINEERING
ENTITY FRAMEWORK CORE 1.0
 Command
dotnet ef dbcontext scaffold -c DbContextName -o ModelsFolder "MyConnectionString"
Microsoft.EntityFrameworkCore.SqlServer –force
 Config dans project.json
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}
ENTITY FRAMEWORK CORE 1.0
 Code généré
public partial class CookBookContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
@"Data Source=mcnltp173;Initial Catalog=CookBook;Integrated Security=True");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Book>(entity =>
{
entity.Property(e => e.Name)
.IsRequired()
.HasColumnType("varchar(50)");
});
}
public virtual DbSet<Book> Book { get; set; }
public virtual DbSet<Recipe> Recipe { get; set; }
}
MICRO ORMS
DAPPER - PETAPOCO - MASSIVE - SIMPLE.DATA - SERVICESTACK.ORMLITE
MICRO ORMS : DAPPER
POCO
DYNAMIC OBJECTS
MULTIPLE RESULTS
STORED PROCEDURE
TRANSACTION
ASYNC
PROVIDERS: SQLLite, SQL CE, Firebird, Oracle, MySQL, PostgreSQL and SQL Server
MICRO ORMS : DAPPER
CONFIG:
public void ConfigureServices(IServiceCollection services)
{
services.Add(new ServiceDescriptor(typeof(IConfiguration),
provider => new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json",
optional: false,
reloadOnChange: true)
.Build(),
ServiceLifetime.Singleton));
services.AddScoped<ICookBookRepository, CookBookRepository>();
}
// ou (v2) :
public static IConfigurationRoot Configuration;
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ICookBookRepository, CookBookRepository>();
}
MICRO ORMS : DAPPER
CTOR:
private readonly IConfiguration _config;
public CookBookRepository(IConfiguration config)
{
_config = config;
}
public IDbConnection Connection
{
get
{
return new SqlConnection(_config.GetConnectionString("DbConnection"););
}
}
// ou (v2) :
public IDbConnection Connection
{
get
{
return new SqlConnection(Startup.Configuration["connectionStrings:DbConnection"]);
MICRO ORMS : DAPPER
REPO:
public IEnumerable<Book> GetAll()
{
using (IDbConnection db = Connection)
{
db.Open();
// version requete Sql
return db.Query<Book>("SELECT * FROM Book").ToList<Book>;
//return await db.QueryAsync<Book>("SELECT * FROM Book");
// version ps
//return db.Query<Book>("GetAllBooks", commandType: CommandType.StoredProcedure);
}
}
MICRO ORMS : DAPPER
public Book GetByID(int id)
{
using (IDbConnection db = Connection)
{
db.Open();
// version requete Sql
string sQuery = "SELECT * FROM Book WHERE Id = @Id";
return db.Query<Book>(sQuery, new { Id = id }).FirstOrDefault();
// version ps
//string sp = "GetBookByID";
//var parameter = new DynamicParameters();
//parameter.Add("@Id", id, dbType: DbType.Int32, direction: ParameterDirection.Input);
//return db.Query<Book>(sp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault();
}
}
MICRO ORMS : DAPPER
public Book GetMultiple(int id)
{
using (IDbConnection db = Connection)
{
db.Open();
// version requete Sql
//string query = "SELECT * FROM Book WHERE Id=@id; SELECT * FROM Recipe WHERE IdBook=@id;";
//var multipleResults = db.QueryMultiple(query, new { id = id });
// version sp
var parameter = new DynamicParameters();
parameter.Add("@id", id, dbType: DbType.Int32, direction: ParameterDirection.Input);
var multipleResults = db.QueryMultiple("GetBookRecipes", parameter,
commandType: CommandType.StoredProcedure);
var book = multipleResults.Read<Book>().SingleOrDefault();
var recipes = multipleResults.Read<Recipe>().ToList();
if (book != null && recipes != null)
book.Recipes = new List<Recipe>(); book.Recipes.AddRange(recipes);
return book;
}
MICRO ORMS : DAPPER
public void Add(Book book)
{
using (IDbConnection db = Connection)
{
db.Open();
var parameter = new DynamicParameters();
parameter.Add("@name", book.Name, dbType: DbType.String, direction: ParameterDirection.Input);
//string sQuery = "INSERT INTO Book (Name) VALUES(@Name)";
// version 1 requete Sql
//db.Execute(sQuery, parameter);
// version 2 requete Sql
//db.Execute(sQuery, book);
// version sp
db.Execute("InsertBook", parameter, commandType: CommandType.StoredProcedure);
}
}
MICRO ORMS : DAPPER
public void Update(Book book)
{
using (IDbConnection db = Connection)
{
db.Open();
var parameters = new DynamicParameters();
parameters.Add("@Id", book.Id, dbType: DbType.Int32, direction: ParameterDirection.Input);
parameters.Add("@Name", book.Name, dbType: DbType.String, direction: ParameterDirection.Input);
string sQuery = "UPDATE Book SET Name = @Name WHERE Id = @Id";
// version 1 requete Sql
//db.Execute(sQuery, parameters, commandType: CommandType.Text);
// version 2 requete Sql
//db.Execute(sQuery, book, commandType: CommandType.Text);
// version sp
db.Execute("UpdateBook", parameters, commandType: CommandType.StoredProcedure);
}
}
MICRO ORMS : DAPPER
public void Delete(int id)
{
using (IDbConnection db = Connection)
{
db.Open();
// version 1 requete Sql
//string sQuery = "DELETE FROM Book WHERE Id = @Id";
//db.Execute(sQuery, new { Id = id });
// version sp
var parameter = new DynamicParameters();
parameter.Add("@Id", id, dbType: DbType.Int32, direction: ParameterDirection.Input);
string sp = "DeleteBook";
db.Execute(sp, parameter, commandType: CommandType.StoredProcedure);
}
}
MICRO ORMS : PETAPOCO
POCO
DYNAMIC OBJECTS MAPPING
MULTIPLE RESULTS
STORED PROCEDURE
TRANSACTION
ASYNC
T4
PROVIDERS: SQL Server, SQL Server CE, MS Access, SQLite, MySQL, MariaDB, PostgreSQL, Firebird DB, and Oracle
APP.CONFIG
MICRO ORMS : PETAPOCO
CONFIG:
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ICookBookRepository, CookBookRepository>();
}
CTOR:
private readonly Database _db;
public CookBookRepository()
{
var connectionString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;
_db = new Database(connectionString, new SqlServerDatabaseProvider());
}
MICRO ORMS : PETAPOCO
REPO:
public IEnumerable<Book> GetAll()
{
using (IDatabase dbConnection = Connection)
{
return _db.Query<Book>("SELECT * FROM Book");
}
}
public Book GetByID(int id)
{
using (IDatabase dbConnection = Connection)
{
return _db.FirstOrDefault<Book>($"SELECT * FROM Book WHERE Id={id}");
}
}
MICRO ORMS : PETAPOCO
public void Add(Book book)
{
using (IDatabase dbConnection = Connection)
{
_db.Insert(book);
}
}
public void Update(Book book)
{
using (IDatabase dbConnection = Connection)
{
_db.Update(book);
}
}
public void Delete(Book book)
{
using (IDatabase dbConnection = Connection)
{
_db.Delete(book);
}
}
MICRO ORMS : MASSIVE
DYNAMIC OBJECTS
MULTIPLE RESULTS
STORED PROCEDURE
TRANSACTION
ASYNC
PROVIDERS: SQL Server, Oracle, SQLite, PostgreSQL
APP.CONFIG
MICRO ORMS : MASSIVE
CONFIG:
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ICookBookRepository, CookBookRepository>();
}
public class Book : DynamicModel
{
public Book():base("DbConnection", "Book","Id") { }
public int Id { get; set; }
public string Name { get; set; }
}
MICRO ORMS : MASSIVE
REPO:
public async Task<IList<dynamic>> GetAll()
{
return await table.AllAsync();
}
public async Task<dynamic> GetByID(int id)
{
return await table.SingleAsync($"WHERE Id={id}");
}
MICRO ORMS : MASSIVE
public async Task Add(dynamic book)
{
await table.InsertAsync(book);
}
public async Task Update(dynamic book)
{
await table.UpdateAsync(book, book.Id);
}
public async Task Delete(int id)
{
await table.DeleteAsync(id);
}
MICRO ORMS : SIMPLE.DATA
POCO
DYNAMIC OBJECTS
MULTIPLE RESULTS
STORED PROCEDURE
TRANSACTION
ASYNC
PROVIDERS: SQL Server, SQL Azure, SQL Server Compact, Oracle, MySQL, SQLite, PostgreSQL, SQLAnywhere, Informix,
MongoDB, OData
MICRO ORMS : SIMPLE.DATA
CONFIG:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
Configuration = builder.Build();
}
public static IConfigurationRoot Configuration;
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ICookBookRepository, CookBookRepository>()
}
CTOR:
private readonly dynamic _db;
public CookBookRepository()
{
_db = Database.OpenConnection(Startup.Configuration["connectionStrings:DbConnection"]);
}
MICRO ORMS : SIMPLE.DATA
REPO:
public async Task<List<Book>> GetAll()
{
return await _db.Book.All().ToList<Book>();
//return await _db["Book"].All().ToList<Book>();
}
public async Task<Book> GetByID(int id)
{
return await _db.Book.Find(_db.Book.Id == id);
//return await _db.Book.Get(id).Cast<Book>();
}
MICRO ORMS : SIMPLE.DATA
public async Task Add(Book book)
{
await _db.Book.Insert(book);
}
public async Task Update(Book book)
{
await _db.Book.UpdateById(Id: book.Id, Name: book.Name);
}
public async Task Delete(int id)
{
await _db.Book.DeleteById(id);
}
MICRO ORMS : SERVICESTACK.ORMLITE
POCO
DYNAMIC OBJECTS
MULTIPLE RESULTS
STORED PROCEDURE
TRANSACTION
ASYNC
PROVIDERS: SqlServer, PostgreSQL, MySql, Sqlite.Mono, Sqlite.Windows, Oracle, Firebird, VistaDb,
AWS RDS (PostgreSQL, Aurora, MySQL, MariaDB, SQL Server)
MICRO ORMS : SERVICESTACK.ORMLITE
CONFIG:
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ICookBookRepository, CookBookRepository>();
}
CTOR:
private readonly IDbConnectionFactory _dbFactory;
public CookBookRepository()
{
_dbFactory = new OrmLiteConnectionFactory(
Startup.Configuration["connectionStrings:DbConnection"],
SqlServer2012Dialect.Provider);
}
MICRO ORM : SERVICESTACK.ORMLITE
REPO:
public IEnumerable<Book> GetAll()
{
using (IDbConnection dbConnection = _dbFactory.OpenDbConnection())
{
return dbConnection.Select<Book>();
//return await dbConnection.SelectAsync<Book>();
}
}
public Book GetByID(int id)
{
using (IDbConnection dbConnection = _dbFactory.OpenDbConnection())
{
return dbConnection.Select<Book>(s => s.Id == id).FirstOrDefault();
//return await dbConnection.SelectAsync<Book>(s => s.Id == id).FirstOrDefault();
}
}
MICRO ORMS : SERVICESTACK.ORMLITE
public void Add(Book book)
{
using (IDbConnection dbConnection = _dbFactory.OpenDbConnection())
{
dbConnection.Insert<Book>(book);
// await dbConnection.InsertAsync<Book>(book);
}
}
public void Delete(int id)
{
using (IDbConnection dbConnection = _dbFactory.OpenDbConnection())
{
dbConnection.Delete<Book>(s => s.Id == id);
// await dbConnection.DeleteAsync<Book>(s => s.Id == id);
}
}
MICRO ORMS : SERVICESTACK.ORMLITE
public void Update(Book book)
{
using (IDbConnection dbConnection = _dbFactory.OpenDbConnection())
{
// dbConnection.Update<Book>(
// dbConnection.UpdateAdd<Book>(
// dbConnection.UpdateAll<Book>(
// await dbConnection.UpdateOnlyAsync<Book>(
dbConnection.UpdateOnly<Book>(
book,
onlyFields: f => f.Name == book.Name,
where: s => s.Id == book.Id
);
}
}
LINKS
 PETAPOCO
 http://www.toptensoftware.com/petapoco/
 https://github.com/CollaboratingPlatypus/PetaPoco
 MASSIVE OK
 https://github.com/FransBouma/Massive
 ORMLITE OK
 https://github.com/ServiceStack/ServiceStack.OrmLite
 http://gistlyn.com/?collection=991db51e44674ad01d3d318b24cf0934&gist=a62b1e7a8da57c7d1fda95b3da5303eb
 SIMPLEDATA OK
 https://github.com/markrendle/Simple.Data
 DAPPER OK
 https://github.com/StackExchange/dapper-dot-net
Ad

More Related Content

What's hot (19)

Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
John David Duncan
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
Deependra Ariyadewa
 
Sequelize
SequelizeSequelize
Sequelize
Tarek Raihan
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
techbed
 
Gl qtp day 3 2
Gl qtp day 3   2Gl qtp day 3   2
Gl qtp day 3 2
Pragya Rastogi
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
John David Duncan
 
Java assgn
Java assgnJava assgn
Java assgn
aa11bb11
 
Testing with Node.js
Testing with Node.jsTesting with Node.js
Testing with Node.js
Jonathan Waller
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Library
doughellmann
 
Mysql
MysqlMysql
Mysql
ksujitha
 
Selectors and normalizing state shape
Selectors and normalizing state shapeSelectors and normalizing state shape
Selectors and normalizing state shape
Muntasir Chowdhury
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
Arturs Drozdovs
 
Hadoop
HadoopHadoop
Hadoop
Naoyuki Kakuda
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no android
Rodrigo de Souza Castro
 
Building android apps with kotlin
Building android apps with kotlinBuilding android apps with kotlin
Building android apps with kotlin
Shem Magnezi
 
Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0
Victor Coustenoble
 
Sqlxml vs xquery
Sqlxml vs xquerySqlxml vs xquery
Sqlxml vs xquery
Amol Pujari
 
Custom faultpolicies
Custom faultpoliciesCustom faultpolicies
Custom faultpolicies
XAVIERCONSULTANTS
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
Jainul Musani
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
John David Duncan
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
Deependra Ariyadewa
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
techbed
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
John David Duncan
 
Java assgn
Java assgnJava assgn
Java assgn
aa11bb11
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Library
doughellmann
 
Selectors and normalizing state shape
Selectors and normalizing state shapeSelectors and normalizing state shape
Selectors and normalizing state shape
Muntasir Chowdhury
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
Arturs Drozdovs
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no android
Rodrigo de Souza Castro
 
Building android apps with kotlin
Building android apps with kotlinBuilding android apps with kotlin
Building android apps with kotlin
Shem Magnezi
 
Sqlxml vs xquery
Sqlxml vs xquerySqlxml vs xquery
Sqlxml vs xquery
Amol Pujari
 

Viewers also liked (20)

Feedback Loops...to infinity, and beyond!
Feedback Loops...to infinity, and beyond!Feedback Loops...to infinity, and beyond!
Feedback Loops...to infinity, and beyond!
Rui Carvalho
 
Рекламные услуги Business Family
Рекламные услуги Business FamilyРекламные услуги Business Family
Рекламные услуги Business Family
Business Family
 
Resumes and cover_letters
Resumes and cover_lettersResumes and cover_letters
Resumes and cover_letters
Jhonelle Babz
 
booklet 4 mac 2012
booklet 4 mac 2012booklet 4 mac 2012
booklet 4 mac 2012
Hanan Bolous
 
Thinks - Monday
Thinks - MondayThinks - Monday
Thinks - Monday
jwickberg
 
Enterprise Node - Code Quality
Enterprise Node - Code QualityEnterprise Node - Code Quality
Enterprise Node - Code Quality
Kurtis Kemple
 
Cultura del agua en Frailes I: conoce tus fuentes y Acuíferos
Cultura del agua en Frailes I: conoce tus fuentes y AcuíferosCultura del agua en Frailes I: conoce tus fuentes y Acuíferos
Cultura del agua en Frailes I: conoce tus fuentes y Acuíferos
TúRInnova @tecnico_turismo
 
You have to want it.
You have to want it.You have to want it.
You have to want it.
Jurex Center for Legal Nurse Consulting
 
Рекламные услуги Business Family
Рекламные услуги Business FamilyРекламные услуги Business Family
Рекламные услуги Business Family
Business Family
 
Интернет маркетинг по новым технологиям
Интернет маркетинг по новым технологиямИнтернет маркетинг по новым технологиям
Интернет маркетинг по новым технологиям
Business Family
 
Taleem(education)
Taleem(education)Taleem(education)
Taleem(education)
AnsibRaza
 
Quien quiere ser millonario emili
Quien quiere ser millonario emiliQuien quiere ser millonario emili
Quien quiere ser millonario emili
Maryory Gomez
 
hubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anak
hubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anakhubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anak
hubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anak
Siti Nurjanah
 
Enterprise Node - Code Discoverability
Enterprise Node - Code DiscoverabilityEnterprise Node - Code Discoverability
Enterprise Node - Code Discoverability
Kurtis Kemple
 
Kombinacni logicka funkce
Kombinacni logicka funkceKombinacni logicka funkce
Kombinacni logicka funkce
Petr Chládek
 
Social Media in the Library, Phnom Penh October 2013
Social Media in the Library, Phnom Penh October 2013Social Media in the Library, Phnom Penh October 2013
Social Media in the Library, Phnom Penh October 2013
LottaRWI
 
Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...
Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...
Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...
Business Family
 
Feedback Loops...to infinity, and beyond!
Feedback Loops...to infinity, and beyond!Feedback Loops...to infinity, and beyond!
Feedback Loops...to infinity, and beyond!
Rui Carvalho
 
Рекламные услуги Business Family
Рекламные услуги Business FamilyРекламные услуги Business Family
Рекламные услуги Business Family
Business Family
 
Resumes and cover_letters
Resumes and cover_lettersResumes and cover_letters
Resumes and cover_letters
Jhonelle Babz
 
booklet 4 mac 2012
booklet 4 mac 2012booklet 4 mac 2012
booklet 4 mac 2012
Hanan Bolous
 
Thinks - Monday
Thinks - MondayThinks - Monday
Thinks - Monday
jwickberg
 
Enterprise Node - Code Quality
Enterprise Node - Code QualityEnterprise Node - Code Quality
Enterprise Node - Code Quality
Kurtis Kemple
 
Cultura del agua en Frailes I: conoce tus fuentes y Acuíferos
Cultura del agua en Frailes I: conoce tus fuentes y AcuíferosCultura del agua en Frailes I: conoce tus fuentes y Acuíferos
Cultura del agua en Frailes I: conoce tus fuentes y Acuíferos
TúRInnova @tecnico_turismo
 
Рекламные услуги Business Family
Рекламные услуги Business FamilyРекламные услуги Business Family
Рекламные услуги Business Family
Business Family
 
Интернет маркетинг по новым технологиям
Интернет маркетинг по новым технологиямИнтернет маркетинг по новым технологиям
Интернет маркетинг по новым технологиям
Business Family
 
Taleem(education)
Taleem(education)Taleem(education)
Taleem(education)
AnsibRaza
 
Quien quiere ser millonario emili
Quien quiere ser millonario emiliQuien quiere ser millonario emili
Quien quiere ser millonario emili
Maryory Gomez
 
hubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anak
hubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anakhubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anak
hubungan tingkat pendidikan orangtua dengan prestasi hasil belajar anak
Siti Nurjanah
 
Enterprise Node - Code Discoverability
Enterprise Node - Code DiscoverabilityEnterprise Node - Code Discoverability
Enterprise Node - Code Discoverability
Kurtis Kemple
 
Kombinacni logicka funkce
Kombinacni logicka funkceKombinacni logicka funkce
Kombinacni logicka funkce
Petr Chládek
 
Social Media in the Library, Phnom Penh October 2013
Social Media in the Library, Phnom Penh October 2013Social Media in the Library, Phnom Penh October 2013
Social Media in the Library, Phnom Penh October 2013
LottaRWI
 
Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...
Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...
Маркетинговые инструменты в продвижении услуг на рынке строительства и недвиж...
Business Family
 
Ad

Similar to Entity Framework Core & Micro-Orms with Asp.Net Core (20)

NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
hameedkhan2017
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
elizhender
 
Hibernate
Hibernate Hibernate
Hibernate
Sunil OS
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
HostedbyConfluent
 
9 Python programming notes for ktu physics and computer application semester 4
9 Python programming notes for ktu  physics and computer application semester 49 Python programming notes for ktu  physics and computer application semester 4
9 Python programming notes for ktu physics and computer application semester 4
ebindboby1
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
Information Technology
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
MongoDB
 
Kerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastKerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit east
Jorge Lopez-Malla
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
Haroon Idrees
 
Dropwizard
DropwizardDropwizard
Dropwizard
Scott Leberknight
 
Java beans
Java beansJava beans
Java beans
Sher Singh Bardhan
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Red Hat Developers
 
Lecture17
Lecture17Lecture17
Lecture17
vantinhkhuc
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
MongoDB
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
Murat Yener
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Mark Needham
 
Jdbc
JdbcJdbc
Jdbc
Indu Lata
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
 
The Developer Conference - CloudKit, entendendo a Cloud da Apple
The Developer Conference - CloudKit, entendendo a Cloud da AppleThe Developer Conference - CloudKit, entendendo a Cloud da Apple
The Developer Conference - CloudKit, entendendo a Cloud da Apple
Rodrigo Leite
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
Hibernate
Hibernate Hibernate
Hibernate
Sunil OS
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
HostedbyConfluent
 
9 Python programming notes for ktu physics and computer application semester 4
9 Python programming notes for ktu  physics and computer application semester 49 Python programming notes for ktu  physics and computer application semester 4
9 Python programming notes for ktu physics and computer application semester 4
ebindboby1
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
MongoDB
 
Kerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastKerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit east
Jorge Lopez-Malla
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
Haroon Idrees
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Red Hat Developers
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
MongoDB
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
Murat Yener
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Mark Needham
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
 
The Developer Conference - CloudKit, entendendo a Cloud da Apple
The Developer Conference - CloudKit, entendendo a Cloud da AppleThe Developer Conference - CloudKit, entendendo a Cloud da Apple
The Developer Conference - CloudKit, entendendo a Cloud da Apple
Rodrigo Leite
 
Ad

Recently uploaded (20)

Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Top 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing ServicesTop 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing Services
Infrassist Technologies Pvt. Ltd.
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 

Entity Framework Core & Micro-Orms with Asp.Net Core

  • 1. ASPNET CORE DATA ACCESS ENTITY FRAMEWORK CORE & MICRO ORMS
  • 2. ETAT DES LIEUX : EF CORE 1.0  Nouvelles plateformes  .NET CORE (ASP.NET Core, UWP)  .NET Framework (ASP.NET, WPF, Windows Forms)  XAMARIN  Windows Phone  Windows Store  MAC  Linux
  • 3. ETAT DES LIEUX : EF CORE 1.0  Nouvelles sources de données  Relationnelles (SQL Server, SQL Lite, SQL Compact, Postgres, MySQL, Oracle)  Non relationnelles (Redis, Azure Table Storage)  InMemory (à utiliser pour les test)  Providers disponibles uniquement pour les SGBD relationnels pour la v 1.0  Possibilité de créer son propre provider
  • 4. ENTITY FRAMEWORK CORE 1.0  On repart de Zero mais on garde le meilleur  Code First  Code First from Database  Approche totalement modulaire  IOC friendly  Totalement Open source comme tout ce qui finit par Core… donc code source disponible sur GitHub et possiblité de contribuer son l’évolution.  EF Core n’est pas production ready
  • 5. ENTITY FRAMEWORK CORE 1.0  Fonctionnalités legacy  Change tracking  Migrations  DbContext API  Linq to Entities  SaveChanges  Fonctionnalités supprimées  EDMX  Entity SQL  Complex Mapping  Migrations automatiques
  • 6. ENTITY FRAMEWORK CORE 1.0  Nouvelles fonctionnalités  Dependency injection  Lancer des Batch avec CUD  Créer des clé étrangères  SQL généré plus propre et plus light  Amélioration des graphes d’objets déconnectés  Fonctionnalités à venir  Mapping des procédures stockées  Lazy loading
  • 7. ENTITY FRAMEWORK CORE 1.0.1 DEMARRAGE
  • 8. ENTITY FRAMEWORK CORE 1.0  Package à installer "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1 "  Création d’un DbContext public class CookBookContext : DbContext { public CookBookContext(DbContextOptions<CookBookContext> options) : base(options) { } public DbSet<Book> Book { get; set; } public DbSet<Recipe> Recipe { get; set; } }
  • 9. ENTITY FRAMEWORK CORE 1.0  Config dans appsettings.json { "ConnectionStrings": { "DbConnection": "Data Source=mcnltp173;Initial Catalog=CookBook;Integrated Security=True" } }  Config dans Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddDbContext<CookBookContext>( options => options.UseSqlServer(Configuration.GetConnectionString("DbConnection"))); }
  • 10. ENTITY FRAMEWORK CORE 1.0  Utilisation public class HomeController : Controller { private readonly CookBookContext _context; public HomeController(CookBookContext context) { _context = context; } public IActionResult Index() { var books = _context.Book.ToList(); return View(books); } }
  • 11. ENTITY FRAMEWORK CORE 1.0.1 REVERSE ENGINEERING
  • 12. ENTITY FRAMEWORK CORE 1.0  Command dotnet ef dbcontext scaffold -c DbContextName -o ModelsFolder "MyConnectionString" Microsoft.EntityFrameworkCore.SqlServer –force  Config dans project.json "dependencies": { "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1", "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final" }, "tools": { "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" }
  • 13. ENTITY FRAMEWORK CORE 1.0  Code généré public partial class CookBookContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer( @"Data Source=mcnltp173;Initial Catalog=CookBook;Integrated Security=True"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Book>(entity => { entity.Property(e => e.Name) .IsRequired() .HasColumnType("varchar(50)"); }); } public virtual DbSet<Book> Book { get; set; } public virtual DbSet<Recipe> Recipe { get; set; } }
  • 14. MICRO ORMS DAPPER - PETAPOCO - MASSIVE - SIMPLE.DATA - SERVICESTACK.ORMLITE
  • 15. MICRO ORMS : DAPPER POCO DYNAMIC OBJECTS MULTIPLE RESULTS STORED PROCEDURE TRANSACTION ASYNC PROVIDERS: SQLLite, SQL CE, Firebird, Oracle, MySQL, PostgreSQL and SQL Server
  • 16. MICRO ORMS : DAPPER CONFIG: public void ConfigureServices(IServiceCollection services) { services.Add(new ServiceDescriptor(typeof(IConfiguration), provider => new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(), ServiceLifetime.Singleton)); services.AddScoped<ICookBookRepository, CookBookRepository>(); } // ou (v2) : public static IConfigurationRoot Configuration; public void ConfigureServices(IServiceCollection services) { services.AddScoped<ICookBookRepository, CookBookRepository>(); }
  • 17. MICRO ORMS : DAPPER CTOR: private readonly IConfiguration _config; public CookBookRepository(IConfiguration config) { _config = config; } public IDbConnection Connection { get { return new SqlConnection(_config.GetConnectionString("DbConnection");); } } // ou (v2) : public IDbConnection Connection { get { return new SqlConnection(Startup.Configuration["connectionStrings:DbConnection"]);
  • 18. MICRO ORMS : DAPPER REPO: public IEnumerable<Book> GetAll() { using (IDbConnection db = Connection) { db.Open(); // version requete Sql return db.Query<Book>("SELECT * FROM Book").ToList<Book>; //return await db.QueryAsync<Book>("SELECT * FROM Book"); // version ps //return db.Query<Book>("GetAllBooks", commandType: CommandType.StoredProcedure); } }
  • 19. MICRO ORMS : DAPPER public Book GetByID(int id) { using (IDbConnection db = Connection) { db.Open(); // version requete Sql string sQuery = "SELECT * FROM Book WHERE Id = @Id"; return db.Query<Book>(sQuery, new { Id = id }).FirstOrDefault(); // version ps //string sp = "GetBookByID"; //var parameter = new DynamicParameters(); //parameter.Add("@Id", id, dbType: DbType.Int32, direction: ParameterDirection.Input); //return db.Query<Book>(sp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault(); } }
  • 20. MICRO ORMS : DAPPER public Book GetMultiple(int id) { using (IDbConnection db = Connection) { db.Open(); // version requete Sql //string query = "SELECT * FROM Book WHERE Id=@id; SELECT * FROM Recipe WHERE IdBook=@id;"; //var multipleResults = db.QueryMultiple(query, new { id = id }); // version sp var parameter = new DynamicParameters(); parameter.Add("@id", id, dbType: DbType.Int32, direction: ParameterDirection.Input); var multipleResults = db.QueryMultiple("GetBookRecipes", parameter, commandType: CommandType.StoredProcedure); var book = multipleResults.Read<Book>().SingleOrDefault(); var recipes = multipleResults.Read<Recipe>().ToList(); if (book != null && recipes != null) book.Recipes = new List<Recipe>(); book.Recipes.AddRange(recipes); return book; }
  • 21. MICRO ORMS : DAPPER public void Add(Book book) { using (IDbConnection db = Connection) { db.Open(); var parameter = new DynamicParameters(); parameter.Add("@name", book.Name, dbType: DbType.String, direction: ParameterDirection.Input); //string sQuery = "INSERT INTO Book (Name) VALUES(@Name)"; // version 1 requete Sql //db.Execute(sQuery, parameter); // version 2 requete Sql //db.Execute(sQuery, book); // version sp db.Execute("InsertBook", parameter, commandType: CommandType.StoredProcedure); } }
  • 22. MICRO ORMS : DAPPER public void Update(Book book) { using (IDbConnection db = Connection) { db.Open(); var parameters = new DynamicParameters(); parameters.Add("@Id", book.Id, dbType: DbType.Int32, direction: ParameterDirection.Input); parameters.Add("@Name", book.Name, dbType: DbType.String, direction: ParameterDirection.Input); string sQuery = "UPDATE Book SET Name = @Name WHERE Id = @Id"; // version 1 requete Sql //db.Execute(sQuery, parameters, commandType: CommandType.Text); // version 2 requete Sql //db.Execute(sQuery, book, commandType: CommandType.Text); // version sp db.Execute("UpdateBook", parameters, commandType: CommandType.StoredProcedure); } }
  • 23. MICRO ORMS : DAPPER public void Delete(int id) { using (IDbConnection db = Connection) { db.Open(); // version 1 requete Sql //string sQuery = "DELETE FROM Book WHERE Id = @Id"; //db.Execute(sQuery, new { Id = id }); // version sp var parameter = new DynamicParameters(); parameter.Add("@Id", id, dbType: DbType.Int32, direction: ParameterDirection.Input); string sp = "DeleteBook"; db.Execute(sp, parameter, commandType: CommandType.StoredProcedure); } }
  • 24. MICRO ORMS : PETAPOCO POCO DYNAMIC OBJECTS MAPPING MULTIPLE RESULTS STORED PROCEDURE TRANSACTION ASYNC T4 PROVIDERS: SQL Server, SQL Server CE, MS Access, SQLite, MySQL, MariaDB, PostgreSQL, Firebird DB, and Oracle APP.CONFIG
  • 25. MICRO ORMS : PETAPOCO CONFIG: public void ConfigureServices(IServiceCollection services) { services.AddScoped<ICookBookRepository, CookBookRepository>(); } CTOR: private readonly Database _db; public CookBookRepository() { var connectionString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString; _db = new Database(connectionString, new SqlServerDatabaseProvider()); }
  • 26. MICRO ORMS : PETAPOCO REPO: public IEnumerable<Book> GetAll() { using (IDatabase dbConnection = Connection) { return _db.Query<Book>("SELECT * FROM Book"); } } public Book GetByID(int id) { using (IDatabase dbConnection = Connection) { return _db.FirstOrDefault<Book>($"SELECT * FROM Book WHERE Id={id}"); } }
  • 27. MICRO ORMS : PETAPOCO public void Add(Book book) { using (IDatabase dbConnection = Connection) { _db.Insert(book); } } public void Update(Book book) { using (IDatabase dbConnection = Connection) { _db.Update(book); } } public void Delete(Book book) { using (IDatabase dbConnection = Connection) { _db.Delete(book); } }
  • 28. MICRO ORMS : MASSIVE DYNAMIC OBJECTS MULTIPLE RESULTS STORED PROCEDURE TRANSACTION ASYNC PROVIDERS: SQL Server, Oracle, SQLite, PostgreSQL APP.CONFIG
  • 29. MICRO ORMS : MASSIVE CONFIG: public void ConfigureServices(IServiceCollection services) { services.AddScoped<ICookBookRepository, CookBookRepository>(); } public class Book : DynamicModel { public Book():base("DbConnection", "Book","Id") { } public int Id { get; set; } public string Name { get; set; } }
  • 30. MICRO ORMS : MASSIVE REPO: public async Task<IList<dynamic>> GetAll() { return await table.AllAsync(); } public async Task<dynamic> GetByID(int id) { return await table.SingleAsync($"WHERE Id={id}"); }
  • 31. MICRO ORMS : MASSIVE public async Task Add(dynamic book) { await table.InsertAsync(book); } public async Task Update(dynamic book) { await table.UpdateAsync(book, book.Id); } public async Task Delete(int id) { await table.DeleteAsync(id); }
  • 32. MICRO ORMS : SIMPLE.DATA POCO DYNAMIC OBJECTS MULTIPLE RESULTS STORED PROCEDURE TRANSACTION ASYNC PROVIDERS: SQL Server, SQL Azure, SQL Server Compact, Oracle, MySQL, SQLite, PostgreSQL, SQLAnywhere, Informix, MongoDB, OData
  • 33. MICRO ORMS : SIMPLE.DATA CONFIG: public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); Configuration = builder.Build(); } public static IConfigurationRoot Configuration; public void ConfigureServices(IServiceCollection services) { services.AddScoped<ICookBookRepository, CookBookRepository>() } CTOR: private readonly dynamic _db; public CookBookRepository() { _db = Database.OpenConnection(Startup.Configuration["connectionStrings:DbConnection"]); }
  • 34. MICRO ORMS : SIMPLE.DATA REPO: public async Task<List<Book>> GetAll() { return await _db.Book.All().ToList<Book>(); //return await _db["Book"].All().ToList<Book>(); } public async Task<Book> GetByID(int id) { return await _db.Book.Find(_db.Book.Id == id); //return await _db.Book.Get(id).Cast<Book>(); }
  • 35. MICRO ORMS : SIMPLE.DATA public async Task Add(Book book) { await _db.Book.Insert(book); } public async Task Update(Book book) { await _db.Book.UpdateById(Id: book.Id, Name: book.Name); } public async Task Delete(int id) { await _db.Book.DeleteById(id); }
  • 36. MICRO ORMS : SERVICESTACK.ORMLITE POCO DYNAMIC OBJECTS MULTIPLE RESULTS STORED PROCEDURE TRANSACTION ASYNC PROVIDERS: SqlServer, PostgreSQL, MySql, Sqlite.Mono, Sqlite.Windows, Oracle, Firebird, VistaDb, AWS RDS (PostgreSQL, Aurora, MySQL, MariaDB, SQL Server)
  • 37. MICRO ORMS : SERVICESTACK.ORMLITE CONFIG: public void ConfigureServices(IServiceCollection services) { services.AddScoped<ICookBookRepository, CookBookRepository>(); } CTOR: private readonly IDbConnectionFactory _dbFactory; public CookBookRepository() { _dbFactory = new OrmLiteConnectionFactory( Startup.Configuration["connectionStrings:DbConnection"], SqlServer2012Dialect.Provider); }
  • 38. MICRO ORM : SERVICESTACK.ORMLITE REPO: public IEnumerable<Book> GetAll() { using (IDbConnection dbConnection = _dbFactory.OpenDbConnection()) { return dbConnection.Select<Book>(); //return await dbConnection.SelectAsync<Book>(); } } public Book GetByID(int id) { using (IDbConnection dbConnection = _dbFactory.OpenDbConnection()) { return dbConnection.Select<Book>(s => s.Id == id).FirstOrDefault(); //return await dbConnection.SelectAsync<Book>(s => s.Id == id).FirstOrDefault(); } }
  • 39. MICRO ORMS : SERVICESTACK.ORMLITE public void Add(Book book) { using (IDbConnection dbConnection = _dbFactory.OpenDbConnection()) { dbConnection.Insert<Book>(book); // await dbConnection.InsertAsync<Book>(book); } } public void Delete(int id) { using (IDbConnection dbConnection = _dbFactory.OpenDbConnection()) { dbConnection.Delete<Book>(s => s.Id == id); // await dbConnection.DeleteAsync<Book>(s => s.Id == id); } }
  • 40. MICRO ORMS : SERVICESTACK.ORMLITE public void Update(Book book) { using (IDbConnection dbConnection = _dbFactory.OpenDbConnection()) { // dbConnection.Update<Book>( // dbConnection.UpdateAdd<Book>( // dbConnection.UpdateAll<Book>( // await dbConnection.UpdateOnlyAsync<Book>( dbConnection.UpdateOnly<Book>( book, onlyFields: f => f.Name == book.Name, where: s => s.Id == book.Id ); } }
  • 41. LINKS  PETAPOCO  http://www.toptensoftware.com/petapoco/  https://github.com/CollaboratingPlatypus/PetaPoco  MASSIVE OK  https://github.com/FransBouma/Massive  ORMLITE OK  https://github.com/ServiceStack/ServiceStack.OrmLite  http://gistlyn.com/?collection=991db51e44674ad01d3d318b24cf0934&gist=a62b1e7a8da57c7d1fda95b3da5303eb  SIMPLEDATA OK  https://github.com/markrendle/Simple.Data  DAPPER OK  https://github.com/StackExchange/dapper-dot-net