Disabling thread safety check in Entity Framework
In this blog post we will have a look into how to disable the thread safety check in Entity Framework. What are the implications of doing so and how to do it.
In this blog post we will have a look into how to disable the thread safety check in Entity Framework. What are the implications of doing so and how to do it.
Last year I wrote an article about how ToListAsync
was slow in Entity Framework titled: "Be careful with ToListAsync and ToArrayAsync in Entity Framework Core". Things have evolved since then, so let's celebrate!
Long title - short intro? Well - I recently came across my own stupidity and wanted to display that to the world. Basically, how to dynamically selecting a column with Entity Framework.
LINQ has a Join
operator, that basically translates to something like a SQL INNER JOIN. There is no built in operator for a LEFT JOIN in LINQ, but you can achieve the same result by using a combination of GroupJoin
, SelectMany
and DefaultIfEmpty
. But there is a chance that this might change in the future, as there is a proposal to add a LeftJoin
operator in .net 10.
Entity Framework has two methods for converting a query to a list or an array: ToListAsync
and ToArrayAsync
. Of course there is also the sync version of these methods: ToList
and ToArray
. And sometimes, you should use the latter one!
When retrieving data from your database with Entity Framework, there are two major options: ToArray
and ToList
. Besides the different return type, is there any significant difference in performance between the two? Let's find out!
I came across a very annoying "issue" with LINQ joins (left joins) in Entity Framework where the compiler drove me nuts!
In this blog post I will discuss the pros and cons of soft deleting records in a database versus other approaches you can take. Heat up your pop corn and get your salt ready!
Have you ever asked yourself if your EF LINQ queries are susceptible to SQL injection attacks? Either because you are querying some user data from a text field or directly taking whatever your API hits against the database?
From time to time, it is nice to store complex objects or lists as JSON in the database. With Entity Framework 8, this is now easily possible. But this was possible all along with Entity Framework 7.
Pagination is the process of dividing a set into discrete pages. In the context of Entity Framework, that means we are only getting a certain amount of entries from the database.
And we will implement a very easy solution to make that happen in 3 steps. The result will look like this:
var pagedList = DbContext.BlogPosts.ToPagedList(page: 1, pageSize: 5);
Sometimes you have an Id
of an object and want to delete the underlying thing from the database. But it doesn't make sense to load the whole object from the database to memory first. So how can we achieve this quickly?
This edition has the following infographics:
DebuggerDisplayAttribute
ExceptionDispatchInfo
implicit
and explicit
operator