Entity Framework Core logo

How to resolve persistent “Build started… Build failed.” when trying to run Entity Framework Core commands?

This time, I’m happy to present you perhaps the simplest way of fixing an annoying and persistent issue with a misleading error message! Wait, does that sound familiar? It’s almost like that’s what half of my articles are about… Anyway, I was happily going my way about creating a couple of new fields to an entity and then scaffolding my changes to a new migration using Entity Framework Core’s Add-Migration, but this happened: Build started… Build failed. “Oh”, I thought. “I must have messed something…Continue reading How to resolve persistent “Build started… Build failed.” when trying to run Entity Framework Core commands?

WHAT IN TARNATION EF CORE?

How to resolve another “An error occurred while updating the entries” exception in Entity Framework Core

This article offers yet another possible fix to an issue, where trying to call SaveChanges() in Entity Framework Core throws a pretty generic “An error occurred while updating the entries”-exception, and you’re left wondering what in tarnation is wrong this time. And admittedly, that’s a really generic error, so it could be pretty much whatever. But in this article, I’ll go through one possibility. Problem So I was just pushing in some new rows to an incredibly simple table in my small Azure MS SQL…Continue reading How to resolve another “An error occurred while updating the entries” exception in Entity Framework Core

One does not simply use just one DbContext with multiple ConnectionStrings in Entity Framework Core.

How to implement multiple Connection Strings for one DbContext in EF Core?

Recently, while building an app service to host a .NET Core API, I had to implement the logic for using both Read-Only and Read-Write Database Contexts for Entity Framework Core. In this particular case, it was the same database – just different contexts, because depending on the location of the app service the app was deployed in, read and write operations might actually go to different database instances, That’s really easy, right? Well… Yes and no. Essentially, it’s easy to spin up, but comes with…Continue reading How to implement multiple Connection Strings for one DbContext in EF Core?

C# & .NET

How to get the EF Core Connection String?

A while ago, I had a situation where a DbContext was misbehaving after deployed to an Azure App Service, and I needed to check the connection string it’s using directly in the code. However, finding the right method actually took me googling, as there were plenty of examples for Entity Framework for .NET Framework, but next no nothing for Entity Framework Core. Let’s fix that. Long story short, here’s how: Posts Related to “How to get the EF Core Connection String?”:The Scary Anatomy of a…Continue reading How to get the EF Core Connection String?

.NET Core fundamentals in one picture.

How to add creator/modified info to all of your EF models at once in .NET Core

This is a tip that should often be the first thing you do in your projects with database backend, no matter which technology you use: Add some basic info about modified and created times, and the user information – so that if something happens, everyone will know who to blame 😉 There’s a lot of great blog articles describing how to do this in .NET Framework, but not that many for .NET Core. It’s very similar, but not the same. I learned that by copy-pasting…Continue reading How to add creator/modified info to all of your EF models at once in .NET Core

Azure Functions CLI - such a pretty logo for such an awesome functionality

How to access EF’s DbContext in an Azure Function on V2 runtime?

This post describes how you can access your Entity Framework Core model classes and the database context in your Azure Functions. In my example I’m using EF Core 2.1, but the main principle should be the same for later versions as well. Please note, that I use Azure functions runtime 2.x (and so should you!) Another easy one, that I was unable to find much guidance on! But first, let’s start with the basics. Why would you want to have this setup? Why would you…Continue reading How to access EF’s DbContext in an Azure Function on V2 runtime?

.NET logo

How to get the current user in ASP.NET Core?

This post describes how to get the currently logged in user using ASP.NET Core. This is compared with how it’s done in ASP.NET Framework. Background In ASP.NET Core (and .NET Core in general), a lot of things are done a bit differently than what you might be used to if you’re coming from the .NET Framework world. That’s what I’ve been learning building more and more stuff with it, instead of good old .NET Framework. The learning curve is definitely there, but it’s not that…Continue reading How to get the current user in ASP.NET Core?