There are often times when you need to do a refactoring, that Resharper cannot help you with. In my last post I described how regular expressions can be useful: Static refactoring with Visual Studio regular expressions This time the case is different and simple replacement would not work in this case. The default value for… Continue reading Refactoring with reflection
Static refactoring with Visual Studio regular expressions
Regular expressions are a multi-tool in every developer toolbox. One of the places they can be useful is Quick Find and Quick Replace dialogs in Visual Studio. In this post, I’m going to show you how you can use the power of regular expressions in smart refactoring. Changing an enum to string Let’s assume I’d… Continue reading Static refactoring with Visual Studio regular expressions
Returning more than one result from a method – tuple
Have you ever had a case, when you needed to return more than one parameter from a method? There are a couple of ways to cope with that and tuple might just be what you need. The problem Let’s look at the code, where we parse transaction data just to show it on the screen.… Continue reading Returning more than one result from a method – tuple
Bulk copy with Entity Framework Core 5
MS SQL Server provides functionality to quickly insert large amounts of data. It is called Bulk Copy and is performed by SqlBulkCopy class. I already compared how fast is it compared to EF Core 5 in this post: https://www.michalbialecki.com/2020/05/03/entity-framework-core-5-vs-sqlbulkcopy-2/, but this time I want to check something different – linq2db library. What is Linq2db Let’s… Continue reading Bulk copy with Entity Framework Core 5
Entity Framework Core – is it fast?
Entity Framework Core is a great ORM, that recently reached version 5. Is it fast? Is it faster than it’s predecessor, Entity Framework 6, which still offers slightly more functionality? Let’s check that out. This comparison was made by Chad Golden, comparing the performance of adding, updating, and deleting 1000 entities. The exact data and… Continue reading Entity Framework Core – is it fast?
Useful SQL statements when writing EF Core 5 migrations
Entity Framework Core 5 is a great ORM and I love how efficient and concise it is. With the migrations mechanism enabled, you can generate the next migration based on changes applied to your model. This is so cool, but when it comes to other database objects, you are on your own. I mean –… Continue reading Useful SQL statements when writing EF Core 5 migrations
Unit tests in Entity Framework Core 5
Tests are an integral part of software development. These are separate programs that allow you to check if a piece of the program written by us does exactly what it should. Unit tests are small pieces of code that test individual program elements and in Entity Framework Core 5 it’s surprisingly easy to write them.… Continue reading Unit tests in Entity Framework Core 5
How to configure relationships in Entity Framework Core 5
Relationships in a database context define how two entities relate to each other. Entity Framework Core really shines in supporting relationships. It offers a convention-based configuration, that will configure relationships based on the model provided. For more advanced cases we can use robust Fluent API capabilities, that offer greater flexibility. I must admit that working… Continue reading How to configure relationships in Entity Framework Core 5
Read request headers as an object in ASP.Net Core
Reading headers is a standard operation in ASP.NET Core and has been around for ages. I even wrote a post summarizing all methods of passing parameters: ASP.NET Core in .NET 5 – pass parameters to actions. ASP.NET Core introduced handy attributes to handle parameters in controller methods, like [FromQuery] or [FromHeader]. But is there a way… Continue reading Read request headers as an object in ASP.Net Core
How not to pass parameters in Entity Framework Core 5
Recently I wrote a post about executing raw SQL scripts in Entity Framework Core 5: Executing raw SQL with Entity Framework Core 5. One of the readers noticed that I did a big mistake when passing parameters. Let’s take a closed look. I had code like this:
1 2 3 4 5 6 7 8 |
[HttpPost("UpdateProfiles")] public async Task<IActionResult> UpdateProfiles([FromBody] int minimalProfileId = 0) { await primeDbContext.Database.ExecuteSqlRawAsync( $"UPDATE Profiles SET Country = 'Poland' WHERE LEFT(TelNo, 2) = '48' AND Id > {minimalProfileId}"); return Ok(); } |
This method updates profiles Country to Poland, where… Continue reading How not to pass parameters in Entity Framework Core 5