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
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
69
Dockerising ASP.NET Core Applications
tonysneed
1
130
Fun with Visual Studio Code
tonysneed
0
120
Other Decks in Technology
See All in Technology
Exadata Database Service ソフトウェアのアップデートとアップグレードの概要
oracle4engineer
PRO
1
1.2k
ドキュメントからはじめる未来のソフトウェア
pkshadeck
4
1.5k
ReproでのicebergのStreaming Writeの検証と実運用にむけた取り組み
joker1007
0
480
Amazon Bedrock AgentCore EvaluationsでAIエージェントを評価してみよう!
yuu551
0
170
人はいかにして 確率的な挙動を 受け入れていくのか
vaaaaanquish
4
2.6k
開発メンバーが語るFindy Conferenceの裏側とこれから
sontixyou
2
160
【Oracle Cloud ウェビナー】ランサムウェアが突く「侵入の隙」とバックアップの「死角」 ~ 過去の教訓に学ぶ — 侵入前提の防御とデータ保護 ~
oracle4engineer
PRO
2
220
クラウドセキュリティの進化 — AWSの20年を振り返る
kei4eva4
0
160
ゼロから始めたFindy初のモバイルアプリ開発
grandbig
2
240
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
10
72k
最速で価値を出すための プロダクトエンジニアのツッコミ術
kaacun
1
170
AI開発をスケールさせるデータ中心の仕組みづくり
kzykmyzw
0
170
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
280
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
50
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
116
100k
Paper Plane (Part 1)
katiecoart
PRO
0
3.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
43
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Mobile First: as difficult as doing things right
swwweet
225
10k
4 Signs Your Business is Dying
shpigford
187
22k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
190
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