In Entity Framework Core 6 there is a new Unicode attribute which we can use to tell EF to map … Continue reading New Unicode attribute available in Entity Framework Core 6
Category: Entity Framework Blog
Below there’s 70+ Entity Framework blog posts on a large variety of Entity Framework topics including:
- new features coming in upcoming versions of EF.
- performance optimisation topics such as using split queries, and how to select only specific columns.
- architecture topics like should we use the repository pattern over Entity Framework and how can we have private constructors and setters when using DB first.
- how-tos, troubleshooting, useful links, miscellaneous etc.
How to have private constructors and private setters when using Entity Framework Core Database first
Having private constructors and private setters is one of the primary ways we can enforce encapsulation in our domain model. … Continue reading How to have private constructors and private setters when using Entity Framework Core Database first
How to run Entity Framework Core DB scaffolding from a .bat file in Visual Studio
It’s very handy to wrap the Entity Framework Scaffolding command in a bat file and run it on demand from … Continue reading How to run Entity Framework Core DB scaffolding from a .bat file in Visual Studio
Example of an Entity Framework Core Database First development workflow in a team environment
If you’re using Entity Framework Core with the Database First approach you may be looking for a suggested development workflow … Continue reading Example of an Entity Framework Core Database First development workflow in a team environment
Setting audit columns in Entity Framework Core when using the database first approach
It’s a very common use case for applications to have to track when records are created or modified and which … Continue reading Setting audit columns in Entity Framework Core when using the database first approach
How to turn off query tracking on a context level in Entity Framework Core
In Entity Framework Core we’re used to setting AsNoTracking() direct on our queries, but it’s possible to disable tracking on a … Continue reading How to turn off query tracking on a context level in Entity Framework Core
An exception has been raised that is likely due to a transient failure when accessing an Azure SQL Database with Auto-pause on from Entity Framework Core
When you create an Azure SQL Database with the Serverless (pay per second of usage) pricing model there’s an auto-pause … Continue reading An exception has been raised that is likely due to a transient failure when accessing an Azure SQL Database with Auto-pause on from Entity Framework Core
The term ‘Scaffold-DbContext’ is not recognized as the name of a cmdlet, function, script file, or operable program.
If you’re trying to scaffold a database in Entity Framework Core for the first time in your project you might … Continue reading The term ‘Scaffold-DbContext’ is not recognized as the name of a cmdlet, function, script file, or operable program.
Fix the ‘Unable to resolve service for type Microsoft EntityFrameworkCore DbContext’ error after scaffolding an MVC Controller in Visual Studio
If you’ve got this error after scaffolding a controller which uses Entity Framework Core like below… it means you haven’t … Continue reading Fix the ‘Unable to resolve service for type Microsoft EntityFrameworkCore DbContext’ error after scaffolding an MVC Controller in Visual Studio
Customizing SQL Server column types when using Entity Framework Core code first
In Entity Framework when we’re using the code first approach EF will examine our classes and using a defined mapping … Continue reading Customizing SQL Server column types when using Entity Framework Core code first
Using Dependency Injection with Entity Framework DbContext in .NET MVC apps
When using Entity Framework Core and ASP.NET Core MVC we can easily inject a DbContext instance into our controller, repository … Continue reading Using Dependency Injection with Entity Framework DbContext in .NET MVC apps
Labelling Entity Framework Core queries in log files using TagWith
In Entity Framework Core (2.2+) if you’re capturing queries in logs consider using the TagWith feature to output an arbitrary … Continue reading Labelling Entity Framework Core queries in log files using TagWith
Using split queries (AsSplitQuery) in Entity Framework Core to avoid the cartesian explosion problem
Without lazy loading in Entity Framework Core we must eagerly load related entities which means we can experience the ‘cartesian … Continue reading Using split queries (AsSplitQuery) in Entity Framework Core to avoid the cartesian explosion problem
String.FirstOrDefault() LINQ queries now supported in Entity Framework Core 5.0
Entity Framework Core 5.0 now supports the translation of String.FirstOrDefault() LINQ queries. In EF Core 3.1 the following would fail… … Continue reading String.FirstOrDefault() LINQ queries now supported in Entity Framework Core 5.0
Suppress output of OnConfiguring method in Entity Framework Core 5.0
If you’re using Entity Framework Core with the database first approach and re-scaffold you’ll see that by default EF Core … Continue reading Suppress output of OnConfiguring method in Entity Framework Core 5.0
AsNoTracking with identity resolution now available in Entity Framework Core 5.0
AsNoTracking() has been around in Entity Framework for a while. Its ideal to use when pulling back a collection of … Continue reading AsNoTracking with identity resolution now available in Entity Framework Core 5.0
Does using the repository pattern with Entity Framework make sense?
I really enjoyed the Entity Framework Community Standup Ask Me Anything with Julie Lerman the other night (10th March 2021)… … Continue reading Does using the repository pattern with Entity Framework make sense?
How to select specific columns in Entity Framework Core
When writing SQL queries we should avoid SELECT * if we don’t need all columns as it can have a … Continue reading How to select specific columns in Entity Framework Core
Filtered includes now supported in Entity Framework Core 5.0
Filtered includes is an awesome new feature in Entity Framework Core 5.0 which was released in November 2020. Without lazy … Continue reading Filtered includes now supported in Entity Framework Core 5.0
Reading Entity Framework Core connection string from appSettings.json
When you run Scoffold-DbCotext with a connection string EF Core will scaffold your DB but will put the hardcoded connection string … Continue reading Reading Entity Framework Core connection string from appSettings.json
Setting batch size in Entity Framework Core
Entity Framework (pre-core) didn’t support batching of CUD statements, so if you were inserting 100 entities for example, EF sent … Continue reading Setting batch size in Entity Framework Core
View SQL queries run by Entity Framework Core in the console
In Entity Framework Core writing the executed queries to the console is easy. Just create a ILoggerFactory and then configure … Continue reading View SQL queries run by Entity Framework Core in the console
Make entities inherit from a base class in Entity Framework Core DB First
It’s often useful to have our entities inherit from a base class. This is easily done using EF Core Power … Continue reading Make entities inherit from a base class in Entity Framework Core DB First
Excluding tables in Entity Framework Core Scaffold-DbContext command
In Entity Framework Core DB First if you don’t want models created for certain tables you need to explicitly list … Continue reading Excluding tables in Entity Framework Core Scaffold-DbContext command
Setting Global Query Filters on multiple entities dynamically in Entity Framework Core
Since Entity Framework Core 2 we can use Global Query Filters to add where clauses to any queries EF generates … Continue reading Setting Global Query Filters on multiple entities dynamically in Entity Framework Core