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
90
Build Web APIs Faster with .NET Core Scaffolding
tonysneed
0
52
Follow Your IT Dreams
tonysneed
0
68
Dockerising ASP.NET Core Applications
tonysneed
1
130
Fun with Visual Studio Code
tonysneed
0
120
Other Decks in Technology
See All in Technology
さくらのクラウド開発ふりかえり2025
kazeburo
2
1.3k
Keynoteから見るAWSの頭の中
nrinetcom
PRO
1
150
Directions Asia 2025 _ Let’s build my own secretary (AI Agent) Part 1 & 2
ryoheig0405
0
110
2025年 山梨の技術コミュニティを振り返る
yuukis
0
130
なぜ あなたはそんなに re:Invent に行くのか?
miu_crescent
PRO
0
240
AIエージェントを5分で一気におさらい!AIエージェント「構築」元年に備えよう
yakumo
1
130
[2025-12-12]あの日僕が見た胡蝶の夢 〜人の夢は終わらねェ AIによるパフォーマンスチューニングのすゝめ〜
tosite
0
220
Kiro を用いたペアプロのススメ
taikis
4
2.1k
人工知能のための哲学塾 ニューロフィロソフィ篇 第零夜 「ニューロフィロソフィとは何か?」
miyayou
0
210
[PR] はじめてのデジタルアイデンティティという本を書きました
ritou
0
560
AgentCore BrowserとClaude Codeスキルを活用した 『初手AI』を実現する業務自動化AIエージェント基盤
ruzia
7
2.2k
2025年のデザインシステムとAI 活用を振り返る
leveragestech
0
590
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
1
1.5k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1k
The agentic SEO stack - context over prompts
schlessera
0
570
Amusing Abliteration
ianozsvald
0
79
A Modern Web Designer's Workflow
chriscoyier
698
190k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
260
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
180
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Unsuck your backbone
ammeep
671
58k
So, you think you're a good person
axbom
PRO
0
1.9k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
730
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