SlideShare a Scribd company logo
Entity Framework Core
1.x/2.x Advanced
Christian Nagel
https://csharp.christiannagel.com
Topics
Entity Framework .vs. EF Core
Essential Features nicht in Entity
Framework
Viele, viele Code Samples
Christian Nagel
• Training
• Coaching
• Consulting
• Development
• Microsoft MVP
• www.cninnovation.com
• csharp.christiannagel.com
Intro
Compare
Entity Framework
• Long History
• Legacy Code
• Windows only
• Big
• Conventions and "Magic"
• Relational Databases only
Entity Framework Core
• New Code (.NET Core 1.0)
• Modern Patterns
• Multi-Platform
• Smaller Footprint
• Conventions, no "Magic"
• Architecture independent of
relational databases
Code First –
only!
Database first, Model
first not supported
You still can create a
model from a database
dotnet ef scaffold
Logging
• .NET Core Logging
• ILogger, ILoggerFactory
• Add Query Tags (2.2)
• Samples: BooksSample, LazyLoading
DbContext Pools (2.0)
• Connection Strings are pooled
• Creating context can take time
• DbContexts can be pooled
• AddDbContextPool()
• It's just a matter of container configuration
• No change in using the context
• Sample: ContextPoolSample
Model Definition
Model Definition
• Convention
• Annotations (Attributes)
• Fluent API
• Separate configuration type with IEntityTypeConfiguration<T>
Shadow Properties (1.0)
• Are not represented in the model
• Available in database tables
• Can be accessed using the context
• Example Columns
• IsDeleted
• LastUpdated
• TenantId
• Sample App: BooksSample
Model-Level Query Filter
• Define a filter that is included with every query
• Example: IsDeleted, TenantId
• Sample App: BooksSample
Mapping to Fields (1.1)
• Read-only Properties in the model
• Private fields
• Not accessible via Properties
• Constructors with parameters (2.1)
• Sample App: BooksSample
Keyless Entity Types (2.1)
• Kwown as query types before 3.0
• HasNoKey() Fluent API
• Mapped via ToTable() or ToView()
Migrations
• Manage the database from code
• Add migrations for every change
• Includes scaffolding of data
• Migrate:
• context.Database.Migrate()
• dotnet ef database update
• dotnet ef migrations script
• Sample App: MigrationsConsoleApp, MigrationsLib
Relations
Table per Hierarchy (TPH) - Inheritance
• One table per hierarchy
• Conventions
• Base classes and derived classes
• All types DbSet<T> mapped
• Fluent API
• Only abstract base class DbSet<T> mapped
• HasDiscriminator
• HasValue
• Sample: TPHWithConventions / TPHWithFluentAPI
Table Splitting (2.0)
• Multiple types access the same table
• Menu & MenuDetail types in one table
• Fluent API
• HasOne().WithOne().HasForeignKey()
• Sample: TableSplitting
Owned Entities (2.0)
• Owned entities are part of the owner
• Owned attribute (2.1)
• Fluent API
• OwnsOne – define relation
• Sample: OwnedEntities
References
• Eager Loading
• Include relations with a query
• Include() / ThenInclude()
• Explicit Loading
• Load relations on request
• EntityEntry.Reference().Load
• EntityEntry.Collection().Load
• Lazy Loading (2.2)
• Load on property access
Lazy Loading (2.2)
• This feature needs to be explicitly enabled
• NuGet Package Microsoft.EntityFrameworkCore.Proxies
• UseLazyLoadingProxies() with options
• Virtual Properties are required in the model
• Sample: LazyLoading
NoSQL
Azure Cosmos
DB
NoSQL Document Database
Supported by EF Core 3.0
Use one or multiple containers for entities
Create hierarchies of data in one JSON
document: OwnsOne / OwnsMany
Summary
EF Core is ready to use
Multi-Platform, Modern Patterns
Great Features
Relational and NoSQL Provider
Questions?
Entity Framework Core 1.x/2.x Advanced
Thank you!

More Related Content

PDF
C# 8 in Libraries and Applications
PDF
.NET Core 3.0 - What's new?
PDF
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
PDF
C# 8 and .NET Core 3
PDF
Async streams
PDF
C# 9 - What's the cool stuff? - BASTA! Spring 2021
PDF
Azure App Configuration with .NET applications
PDF
Asp.Net 3.5 Part 2
C# 8 in Libraries and Applications
.NET Core 3.0 - What's new?
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
C# 8 and .NET Core 3
Async streams
C# 9 - What's the cool stuff? - BASTA! Spring 2021
Azure App Configuration with .NET applications
Asp.Net 3.5 Part 2

What's hot (20)

PPTX
Domain Specific Development using T4
PDF
RubyConf Taiwan 2016 - Large scale Rails applications
PPTX
Migration from ASP.NET MVC to ASP.NET Core
PPTX
A (XPages) developers guide to Cloudant
PDF
RubyConf China 2015 - Rails off assets pipeline
PPTX
DEV-1129 How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Rea...
PDF
.net Core 3.0 ve C# 8.0
PPTX
TypeScript and Angular2 (Love at first sight)
PDF
LINEデリマでのElasticsearchの運用と監視の話
PDF
Reference Semantics with C# and .NET Core
PPTX
Porting ASP.NET applications to Windows Azure
PPTX
Build your datatypes
PDF
BladeRunnerJS Show & Tell
PPTX
Api mation
PDF
Clovaを支える技術 機械学習配信基盤のご紹介
PPTX
4. introduction to Asp.Net MVC - Part II
PPTX
Testing Testing everywhere
PDF
Scaling Yii2 Application
PDF
GlueCon 2015 - Publish your SQL data as web APIs
PPTX
Kotlin db migration tool
Domain Specific Development using T4
RubyConf Taiwan 2016 - Large scale Rails applications
Migration from ASP.NET MVC to ASP.NET Core
A (XPages) developers guide to Cloudant
RubyConf China 2015 - Rails off assets pipeline
DEV-1129 How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Rea...
.net Core 3.0 ve C# 8.0
TypeScript and Angular2 (Love at first sight)
LINEデリマでのElasticsearchの運用と監視の話
Reference Semantics with C# and .NET Core
Porting ASP.NET applications to Windows Azure
Build your datatypes
BladeRunnerJS Show & Tell
Api mation
Clovaを支える技術 機械学習配信基盤のご紹介
4. introduction to Asp.Net MVC - Part II
Testing Testing everywhere
Scaling Yii2 Application
GlueCon 2015 - Publish your SQL data as web APIs
Kotlin db migration tool
Ad

Similar to Entity Framework Core 1.x/2.x Advanced (20)

PPTX
Entity Core with Core Microservices.pptx
PDF
.NET Core, ASP.NET Core Course, Session 13
PPTX
A Tour of EF Core's (1.1) Most Interesting & Important Features
PPTX
Academy PRO: Entity Framework Сore
PDF
.NET Core, ASP.NET Core Course, Session 17
PPTX
Entity Framework 4
PDF
.NET Core, ASP.NET Core Course, Session 16
PPTX
05 entity framework
PPTX
Entity Framework for Cross platform apps
PPT
Entity Framework 4 In Microsoft Visual Studio 2010
PPTX
Entity framework
PPTX
Entity Framework
PPTX
EF6 or EF Core? How Do I Choose?
PPTX
Entity Framework Core
PPTX
Introducing Entity Framework 4.0
PDF
Entity Framework 6 Recipes 2nd Edition Brian Driscoll
PPTX
Using entity framework core in .net
PDF
Entity Framework Interview Questions PDF By ScholarHat
PPTX
Entity Frame Work Core.pptx
PPTX
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Core with Core Microservices.pptx
.NET Core, ASP.NET Core Course, Session 13
A Tour of EF Core's (1.1) Most Interesting & Important Features
Academy PRO: Entity Framework Сore
.NET Core, ASP.NET Core Course, Session 17
Entity Framework 4
.NET Core, ASP.NET Core Course, Session 16
05 entity framework
Entity Framework for Cross platform apps
Entity Framework 4 In Microsoft Visual Studio 2010
Entity framework
Entity Framework
EF6 or EF Core? How Do I Choose?
Entity Framework Core
Introducing Entity Framework 4.0
Entity Framework 6 Recipes 2nd Edition Brian Driscoll
Using entity framework core in .net
Entity Framework Interview Questions PDF By ScholarHat
Entity Frame Work Core.pptx
Entity Framework: Nakov @ BFU Hackhaton 2015
Ad

More from Christian Nagel (15)

PDF
C# 9 and 10 - What's cool?
PDF
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
PDF
Gemeinsame View-Models mit XAML Technologien
PDF
Adaptive Cards - User Interfaces with JSON
PDF
Reference Semantik mit C# und .NET Core - BASTA 2019
PDF
C# What's next? (7.x and 8.0)
PDF
C# 7.x What's new and what's coming with C# 8
PDF
Blazor - The New Silverlight?
PDF
Desktop Bridge with WPF - One way to build modern apps with WPF
PDF
C# - What's next
PDF
Business Apps with the Universal Windows Platform
PDF
Blazor - The New Silverlight?
PDF
Was is Docker? Or: Docker for Software Developers
PDF
Moderne Business Apps mit XAML - oder mit WPF für die Zukunft geplant
PDF
C# - What's Next?
C# 9 and 10 - What's cool?
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
Gemeinsame View-Models mit XAML Technologien
Adaptive Cards - User Interfaces with JSON
Reference Semantik mit C# und .NET Core - BASTA 2019
C# What's next? (7.x and 8.0)
C# 7.x What's new and what's coming with C# 8
Blazor - The New Silverlight?
Desktop Bridge with WPF - One way to build modern apps with WPF
C# - What's next
Business Apps with the Universal Windows Platform
Blazor - The New Silverlight?
Was is Docker? Or: Docker for Software Developers
Moderne Business Apps mit XAML - oder mit WPF für die Zukunft geplant
C# - What's Next?

Recently uploaded (20)

PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
medical staffing services at VALiNTRY
PPTX
Introduction to Artificial Intelligence
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
L1 - Introduction to python Backend.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Nekopoi APK 2025 free lastest update
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
How to Migrate SBCGlobal Email to Yahoo Easily
How Creative Agencies Leverage Project Management Software.pdf
medical staffing services at VALiNTRY
Introduction to Artificial Intelligence
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Digital Strategies for Manufacturing Companies
L1 - Introduction to python Backend.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Nekopoi APK 2025 free lastest update
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Wondershare Filmora 15 Crack With Activation Key [2025
Operating system designcfffgfgggggggvggggggggg
Online Work Permit System for Fast Permit Processing
Softaken Excel to vCard Converter Software.pdf
CHAPTER 2 - PM Management and IT Context

Entity Framework Core 1.x/2.x Advanced

  • 1. Entity Framework Core 1.x/2.x Advanced Christian Nagel https://csharp.christiannagel.com
  • 2. Topics Entity Framework .vs. EF Core Essential Features nicht in Entity Framework Viele, viele Code Samples
  • 3. Christian Nagel • Training • Coaching • Consulting • Development • Microsoft MVP • www.cninnovation.com • csharp.christiannagel.com
  • 5. Compare Entity Framework • Long History • Legacy Code • Windows only • Big • Conventions and "Magic" • Relational Databases only Entity Framework Core • New Code (.NET Core 1.0) • Modern Patterns • Multi-Platform • Smaller Footprint • Conventions, no "Magic" • Architecture independent of relational databases
  • 6. Code First – only! Database first, Model first not supported You still can create a model from a database dotnet ef scaffold
  • 7. Logging • .NET Core Logging • ILogger, ILoggerFactory • Add Query Tags (2.2) • Samples: BooksSample, LazyLoading
  • 8. DbContext Pools (2.0) • Connection Strings are pooled • Creating context can take time • DbContexts can be pooled • AddDbContextPool() • It's just a matter of container configuration • No change in using the context • Sample: ContextPoolSample
  • 10. Model Definition • Convention • Annotations (Attributes) • Fluent API • Separate configuration type with IEntityTypeConfiguration<T>
  • 11. Shadow Properties (1.0) • Are not represented in the model • Available in database tables • Can be accessed using the context • Example Columns • IsDeleted • LastUpdated • TenantId • Sample App: BooksSample
  • 12. Model-Level Query Filter • Define a filter that is included with every query • Example: IsDeleted, TenantId • Sample App: BooksSample
  • 13. Mapping to Fields (1.1) • Read-only Properties in the model • Private fields • Not accessible via Properties • Constructors with parameters (2.1) • Sample App: BooksSample
  • 14. Keyless Entity Types (2.1) • Kwown as query types before 3.0 • HasNoKey() Fluent API • Mapped via ToTable() or ToView()
  • 15. Migrations • Manage the database from code • Add migrations for every change • Includes scaffolding of data • Migrate: • context.Database.Migrate() • dotnet ef database update • dotnet ef migrations script • Sample App: MigrationsConsoleApp, MigrationsLib
  • 17. Table per Hierarchy (TPH) - Inheritance • One table per hierarchy • Conventions • Base classes and derived classes • All types DbSet<T> mapped • Fluent API • Only abstract base class DbSet<T> mapped • HasDiscriminator • HasValue • Sample: TPHWithConventions / TPHWithFluentAPI
  • 18. Table Splitting (2.0) • Multiple types access the same table • Menu & MenuDetail types in one table • Fluent API • HasOne().WithOne().HasForeignKey() • Sample: TableSplitting
  • 19. Owned Entities (2.0) • Owned entities are part of the owner • Owned attribute (2.1) • Fluent API • OwnsOne – define relation • Sample: OwnedEntities
  • 20. References • Eager Loading • Include relations with a query • Include() / ThenInclude() • Explicit Loading • Load relations on request • EntityEntry.Reference().Load • EntityEntry.Collection().Load • Lazy Loading (2.2) • Load on property access
  • 21. Lazy Loading (2.2) • This feature needs to be explicitly enabled • NuGet Package Microsoft.EntityFrameworkCore.Proxies • UseLazyLoadingProxies() with options • Virtual Properties are required in the model • Sample: LazyLoading
  • 22. NoSQL
  • 23. Azure Cosmos DB NoSQL Document Database Supported by EF Core 3.0 Use one or multiple containers for entities Create hierarchies of data in one JSON document: OwnsOne / OwnsMany
  • 24. Summary EF Core is ready to use Multi-Platform, Modern Patterns Great Features Relational and NoSQL Provider