Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
EF Core with Patterns
Search
Anthony Sneed
February 27, 2018
Technology
280
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
EF Core with Patterns
Talk by Tony Sneed and Long Le to ASP.NET Dev Group in Dallas Feb 2018.
Anthony Sneed
February 27, 2018
More Decks by Anthony Sneed
See All by Anthony Sneed
Build Web APIs Faster with .NET Core Scaffolding
tonysneed
0
110
Build Web APIs Faster with .NET Core Scaffolding
tonysneed
0
72
Follow Your IT Dreams
tonysneed
0
81
Dockerising ASP.NET Core Applications
tonysneed
1
150
Fun with Visual Studio Code
tonysneed
0
140
Other Decks in Technology
See All in Technology
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
350
go-sqletch
moznion
0
140
Running Kotlin + Quarkus with Lambda
nealle
1
3.8k
ウォンテッドリーの最近のプロダクトと技術の紹介
stomk
0
100
しろおびから始める!ログ活用の第一歩
shumei_ito
0
950
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
110
今さら理解するウェブフォントver.2026
takanorip
3
840
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
300
How to Design Configuration for Rails Applications
willnet
1
810
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
870
パッチ更新でterraform initが落ちた日
grimoh
1
140
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
440
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Evolving SEO for Evolving Search Engines
ryanjones
0
330
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
570
New Earth Scene 8
popppiees
4
2.7k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
480
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
730
How to make the Groovebox
asonas
2
2.5k
Unsuck your backbone
ammeep
672
58k
From π to Pie charts
rasagy
1
400
Transcript
Entity Framework Core With Design Patterns Anthony Sneed with Long
Le
About Tony • Independent Consultant @ Pioneer Natural Resources •
Coding C# since v1 • Author / Instructor: DevelopMentor, Wintellect • Open Source: URF, Trackable Entities ASPNET Core, EF Core • blog.TonySneed.com • Twitter: @tonysneed
About Le • Principle Architect @ Pioneer Natural Resources •
Currently geeking out w/ MEAN & .NET Core • Open Source: URF.Core, Trackable Entities • blog.longle.io • Twitter: @lelong37
Part 1: Intro to EF Core
EF Core: Not Your Father’s EF • Re-written from the
ground up! • .NET Standard 2.0 • Cross-Platform, Containers, Cloud Friendly • Modern, Modular, Extensible • Lightweight, Performant
EF Core: What’s Hot? • Cross Platform, Container / Cloud
Friendly • Batching update statements • In-memory provider (mockless testing) • Mixing client / server query evaluation • Mixing raw SQL and LINQ expressions • Customizable conventions, migrations
EF Core: What’s Dropped? • EDMX Models, Entity SQL (vs
code-based modeling) • Mapping stored procedures to CUD operations • Many-to-Many without intermediate entity • Full support for geospatial • Built-in design tools and wizards • Table-per-type inheritance mapping (TPH supported)
EF Core vs EF 6 • EF 6 still supported,
but considered legacy • Use EF Core for new ASP.NET Core API’s • Feature-by-feature EF 6 vs Core comparison: https://docs.microsoft.com/en-us/ef/efcore-and- ef6/features
Migrate from EF6 to Core? Don’t even think about it!
EF Core 2.x: What’s New? • GroupBy query translation •
Lazy Loading • Scaffold context and entities separately* • System.Transactions support • Table-splitting, owned types, db scalar functions • Compiled queries, context pooling * Tony’s contrib :)
EF Core Power Tools • Reverse engineer • Visualize model
• Customize entity classes (Handlebars templates*) * Tony’s contrib :)
None
Part 2: Design Patterns for EF Core
Why Patterns? • Using EF directly couples your app to
EF • Newing up DbContext makes your app less testable
Repository Pattern • Repository interfaces decouple app from persistence concerns
Sample Repository public class ProductRepository : IProductRepository { private readonly
NorthwindContext _dbContext; public ProductRepository(NorthwindContext dbContext) { _dbContext = dbContext; } public async Task<Product> FindAsync(int id) { return await _dbContext.Products.FindAsync(id); } }
Marking Changes public void Insert(Product product) { // Mark Added
_dbContext.Products.Add(product); } public void Update(Product product) { // Mark Modified _dbContext.Products.Update(product); } public async Task Delete(int id) { // Mark Deleted var product = await _dbContext.Products.FindAsync(id) _dbContext.Products.Remove(product); }
Unit of Work Pattern • Save changes from multiple repositories
• Wrapped in a single transaction
Persisting Changes public interface IUnitOfWork { Task<int> SaveChangesAsync(); }
Dependency Injection • DI container responsible for supplying instances •
DI is built into ASP.NET and EF Core
Helpful Frameworks • URF: Generic Unit of Work and Repository
https://github.com/urfnet/URF.Core
Helpful Frameworks • Trackable Entities: N-Tier Support for EF Core
https://github.com/TrackableEntities/ TrackableEntities.Core
None
Thank You! Tony Sneed: @tonysneed Long Le: @lelong37 Slides: https://speakerdeck.com/tonysneed/ef-core-with-patterns
Bits: https://github.com/tonysneed/Demo.EfCore.Patterns