X

.NET

Global usings in C# 10

One of the new features in .NET 6 is support for global using declarations. We can define using declarations as global and they work all over the project so we don’t have to define them in other files anymore. Here’s how it works.

Cost of exceptions

Hopefully the era of leprosy and corona is over for this time and it’s time to get back to blogging. Exceptions are powerful feature of object-oriented languages as far as they are used like they are thought to use – throw exception only when something really unexpected happens. This advice should be taken seriously – here’s why.

Top-level programs in C# 9.0

C# 9.0 comes with nice new feature called top-level programs. It’s something that teachers of beginner classes will love for sure. Imagine – you start teaching C# with only two lines of code on screen. All missing code is generated by compiler. This blog post introduces top-level programs and shows some secrets of new C# compiler.

Logging to Notepad window from ASP.NET Core

Something funny to end this week. When checking my Twitter feeds I found a kinky tweet about logging .NET Core messages to Notepad window. Yes, you heard right – .NET Core logger for Notepad. It’s not real, you want to say, but it is. And here’s how it works :)

Xamarin Forms turns to .NET MAUI – single project and code-base dev experience

Yesterday Microsoft announced .NET Multi-platform App UI (MAUI) – the effort to turn Xamarin Forms apps use single cross-platform code-base targeting multiple platforms. Demos from Build conference yesterday gave clear signal – it’s not just an experiment but real deal. They really had single project running on Windows desktop and iPhone. This blog post is short overview of what’s coming.

Using data from MSSQL linked server with EF Core

My previous blog post Querying MySQL from SQL Server using linked server introduced how to link MySQL database to MSSQL and how to write queries that gather data from local and linked server. This blog post demonstrates how to get data mixed from those sources to Entity Framework Core.

Implementing repository querying interface in EF Core DbContext

My last bold statement was that we don’t need custom unit of work and repository classes with Entity Framework Core. One issue remained unsolved and it was querying part of repositories (yeah, those custom querying methods). After some experiments to get querying interface of repositories to DbContext I worked out something that I kind of like. I managed to make DbContext to work like classic unit of work that hosts repository instances. Here’s my experiment and the solution I worked out.

Behind the compiler: 20 examples of C# code before and after compiling

Over years I have written many blog posts about C# and .NET that demonstrate also how things work internally and what C# compiler produces from the code we write. I have called these chapters usually as “Behind the compiler”. This post is growing list of my writings covering interesting findings about C# compiler work.

Execute raw SQL commands in Entity Framework Core

I have never seen a real-life project where object-relational mapper generates 100% of needed SQL. There have always been those special cases when custom SQL commands are needed. In this post I will demonstrate how to run custom SQL commands in Entity Framework Commands and how to read data from database without DbSet and query types.

Using Windows Forms DataGridView in .NET Core 3.1

Windows Forms is coming to .NET Core and last version of Visual Studio 2019 Preview comes with form designer built in. There are basic controls available in toolbox but not all out-of-box controls have made their way there. One of these is DataGridView. Although not shown in toolbox, DataGridView still works like expected. Here’s how I made it work.