Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
EF Core with Patterns
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Anthony Sneed
February 27, 2018
Technology
0
250
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
Tweet
Share
More Decks by Anthony Sneed
See All by Anthony Sneed
Build Web APIs Faster with .NET Core Scaffolding
tonysneed
0
91
Build Web APIs Faster with .NET Core Scaffolding
tonysneed
0
53
Follow Your IT Dreams
tonysneed
0
70
Dockerising ASP.NET Core Applications
tonysneed
1
130
Fun with Visual Studio Code
tonysneed
0
120
Other Decks in Technology
See All in Technology
配列に見る bash と zsh の違い
kazzpapa3
1
120
インフラエンジニア必見!Kubernetesを用いたクラウドネイティブ設計ポイント大全
daitak
0
330
小さく始めるBCP ― 多プロダクト環境で始める最初の一歩
kekke_n
1
370
外部キー制約の知っておいて欲しいこと - RDBMSを正しく使うために必要なこと / FOREIGN KEY Night
soudai
PRO
12
5k
Bill One急成長の舞台裏 開発組織が直面した失敗と教訓
sansantech
PRO
2
310
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
210
AWS Network Firewall Proxyを触ってみた
nagisa53
0
160
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
340
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
290
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
160
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
220
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
460
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
The Curious Case for Waylosing
cassininazir
0
230
Mobile First: as difficult as doing things right
swwweet
225
10k
Fireside Chat
paigeccino
41
3.8k
Designing for humans not robots
tammielis
254
26k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
55
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
270
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Game over? The fight for quality and originality in the time of robots
wayneb77
1
110
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
100
Navigating Weather and Climate Data
rabernat
0
100
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