dotnetcore

Hidden NET 9 gems

Hidden NET 9 gems

Introduction When Microsoft announces a new version of the NET Framework there are release notes. The release notes do not cover all new additions and/or features. This article will introduce several new features with C# samples. Enumerable.Index<T> Enumerable.Index<T> returns an enumerable that incorporates the element's index into a tuple. Before working with Index<T>, there is the conventional route which is declaring a int variable with a value of -1 and increment the variable in a foreach. Note This is what many seasoned developers use and may very well dislike the new Index extension method as they are set in their…
Read More
List all Visual Studio solutions

List all Visual Studio solutions

Introduction Learn how to get started with file globbing by creating a console project to list all Visual Studio solutions (.sln) under a specific folder along with project names for the solution exported to a json file. The reason for using solution and project files is that every reader here using Microsoft Visual Studio should have at least two while if the example were for Word documents or specific image types the code presented may not work so well. Other opportunities besides using a conventual console project there are commandline dotnet tools C# .NET Tools with System.CommandLine which the code…
Read More
Blazor’s Authorization

Blazor’s Authorization

Disclaimer: based on my observation, not readings. Recently, I had to implement Firebase authentication for a Blazor WASM project. To my surprise, I discovered there's no ready-made authentication library for Firebase on .NET. While I found the Firebase Admin library, it wasn't quite what I needed for client-side authentication. So, I ended up building my own solution for .NET. Fortunately, I didn't have to start from scratch. Firebase provides a JavaScript SDK for authentication, which is quite straightforward to use and integrates well with Blazor WASM. Blazor handles authorization through a class derived from AuthenticationStateProvider. This class requires you to…
Read More
Implementing Real-Time Updates with Server-Sent Events (SSE) in C# .NET: A Complete Guide

Implementing Real-Time Updates with Server-Sent Events (SSE) in C# .NET: A Complete Guide

Introduction Server-Sent Events (SSE) is a web technology where the server pushes real-time updates to the client over HTTP, making it ideal for scenarios that require continuous updates, such as live stock prices, notifications, and activity feeds. Unlike WebSockets, SSE is unidirectional (server-to-client) and uses a persistent HTTP connection to send data as events. In .NET Core (C#), SSE can be implemented easily using asynchronous streams, providing a lightweight and scalable solution for real-time applications. This article covers how to implement SSE in C# .NET, detailing the steps involved, best practices to follow, and a conclusion on when to use…
Read More
EF Core queries for unmapped types

EF Core queries for unmapped types

Introduction Learn how to return unmapped types using SqlQuery which may be useful when mapped types are not sufficient. There are several overloads for SqlQuery, here we will use the following along with SqlQueryRaw which is not recommended as unlike SqlQery will leave parameters exposed to hackers. SqlQuery Create the SQL statement, in this case the SQL is to get all United States holidays in a given year. public static FormattableString GetHolidays(int year) => $""" SELECT CalendarDate, CalendarDateDescription AS [Description], CalendarMonth, DATENAME(MONTH, DATEADD(MONTH, CalendarMonth, -1)) AS [Month], CalendarDay AS [Day], DayOfWeekName, IIF(BusinessDay = 0, 'No', 'Yes') AS BusinessDay, IIF(Weekday =…
Read More
NodaTime – time offsets C#

NodaTime – time offsets C#

Introduction NodaTime is an NuGet package devoted to working with dates and times. In this article a cursory look at working with time zones is done. Yes, .NET Framework handles time zone while NodaTime does a more precise handling of time zones. With power and precision of NodaTime comes with it documentation not geared to developers who rarely read documentation and developers who just do not care to read documentation. For these developers it is a must to read NodaTime documentation and experiment. Here code will be presented in a class project and ran in a console project to keep…
Read More
{IL} –> {Intermediate Language}

{IL} –> {Intermediate Language}

IL (Intermediate Language) .NET’dagi oraliq til boʻlib, MSIL (Microsoft Intermediate Language) yoki CIL (Common Intermediate Language) nomi bilan ham tanilgan. C# yoki VB.NET kabi tillardagi manba kodi to'g'ridan-to'g'ri mashina kodiga emas, balki birinchi navbatda ILga kompilyatsiya qilinadi va bu uni platformadan mustaqil qiladi. Arxitektura mustaqilligi: IL kodi CLR (Common Language Runtime) ning tegishli versiyasi o'rnatilgan har qanday platformada ishlashi mumkin. Bu ishlab chiquvchilarga kodni bir marta yozish va uni turli xil operatsion tizimlar va protsessor arxitekturalarida ishga tushirish imkonini beradi. JIT kompilyatsiyasi: Dastur ishga tushirilganda, IL JIT kompilyatori (Just-In-Time kompilyatori) yordamida mashina kodiga aylantiriladi. Ushbu jarayon maqsadli platformada optimal ishlashni…
Read More
EF Core 8 Update Entity

EF Core 8 Update Entity

When entities are being tracked (this is the default, to track changes) EF Core is efficient with updates in that if there are several properties for a model and only one or two properties changed the update statement only updates those columns/properties which changed rather than every column/property. Model public partial class Person { public int Id { get; set; } public string Title { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateOnly BirthDate { get; set; } } Enter fullscreen mode Exit fullscreen mode Example 1 Read data.…
Read More
No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.