csharp

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
Dica C#: Target-Typed New Expressions

Dica C#: Target-Typed New Expressions

Vamos falar sobre Target-Typed New Expressions, uma funcionalidade do C# 9 que torna a inicialização de objetos mais concisa e clara. Veja o exemplo no código abaixo. public class Pessoa { public string Nome { get; set; } public int Idade { get; set; } } public class Program { public static void Main() { Pessoa pessoa = new("João", 30); // Usando Target-Typed New Expressions Console.WriteLine($"Nome: {pessoa.Nome}, Idade: {pessoa.Idade}"); } } Enter fullscreen mode Exit fullscreen mode Explicação:Com Target-Typed New Expressions, você pode omitir o tipo explícito ao criar novos objetos, desde que o tipo possa ser inferido a partir…
Read More
Microservices: Pub/Sub with Dapr, docker-compose, and .NET

Microservices: Pub/Sub with Dapr, docker-compose, and .NET

Wolf Fact: Wolves and domestic dogs share about 99.8% of their DNA, making them closely related. Prerequisites: C#, basic of Web API, Visual Studio, Docker Desktop Publish and Subscribe Pattern:- It defines brokers, publishers, and subscribers, and how they should interact to create a loosely coupled scalable system. The publisher forwards the content/messages to the broker. And the subscribers get these messages from the broker. The Pub/Sub pattern can be implemented in a variety of ways. Ex.- The broker may push messages to subscribers or subscribers may have to read messages from the broker. Like this, every step’s process depends…
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
Understanding ArgumentNullException in C#

Understanding ArgumentNullException in C#

What Does "ArgumentNullException" Mean? In layman's terms, an ArgumentNullException occurs when a method expects you to give it something (an argument), but you give it nothing (null). It's like being asked to bring a dish to a potluck dinner, but you show up empty-handed. Real-Life AnalogyImagine you are invited to a potluck dinner. The host asks everyone to bring a dish to share. If you show up without any food, it's like you brought "nothing" to the table. The host might be frustrated because the event relies on everyone contributing. Similarly, when a method expects an argument and you pass…
Read More
Breaking a TOTP?

Breaking a TOTP?

This post is written to raise awareness of the possible vulnerabilities of RFC 2638. Any code provided here is not intended to be used for malicious purposes and is merely a proof-of-concept and/or example to aid the understanding of the article. RFC 2638: What is it? In their words, This document describes an extension of the One-Time Password (OTP) algorithm, namely the HMAC-based One-Time Password (HOTP) algorithm, as defined in RFC 4226, to support the time-based moving factor. The HOTP algorithm specifies an event-based OTP algorithm, where the moving factor is an event counter. The present work bases the moving…
Read More
Introduction to Object-Relational Mappers (ORMs)

Introduction to Object-Relational Mappers (ORMs)

When working with databases in software development, you often need to store, retrieve, update, and delete data. Traditionally, this involves writing SQL queries, which can be time-consuming and error-prone, especially in complex applications. Object-Relational Mappers, or ORMs, provide a solution to this by simplifying how you interact with databases. In this article, we'll explore what ORMs are, why they are useful, and when to use them. We'll also look at some popular ORM libraries in the .NET ecosystem, along with their pros and cons. What is an ORM? An Object-Relational Mapper (ORM) is a tool that allows developers to interact…
Read More
How to encrypt Strings in .NET code obfuscation?

How to encrypt Strings in .NET code obfuscation?

The string encryption function enables the encryption of literal string data type values. You can choose to encrypt all strings or mark certain strings for obfuscation. Additionally, you have the option to select a cryptographic method for encrypting the strings. Only the strings specified will be encrypted or obfuscated. Discussing the Skater .NET Obfuscator, it's evident that strings can offer significant hints to anyone attempting to reverse-engineer code, so safeguarding string data is crucial. While it won't stop a determined hacker from decoding the strings and accessing the data, it can hinder an attacker's efforts to crack a licensing routine,…
Read More
Data types – ma’lumot turlari.

Data types – ma’lumot turlari.

integer -> int: Enter fullscreen mode Exit fullscreen mode Bu butun sonlar uchun ishlatiladi. Long: Enter fullscreen mode Exit fullscreen mode Bu butun sonlar uchun ishlatiladi. Hotirani kuchaytirib beradi. short: Enter fullscreen mode Exit fullscreen mode Butun sonlar uchun ishlatiladi. double: Enter fullscreen mode Exit fullscreen mode Kasr sonlar uchun ishlatiladi. float: Enter fullscreen mode Exit fullscreen mode Kasr sonlar uchun ishlatiladi. string: Enter fullscreen mode Exit fullscreen mode Tekst va matnlar uchun ishlatiladi. char: Enter fullscreen mode Exit fullscreen mode Bu belgilar uchun ishlatiladi. Data typelarning xotiradagi joyi: Enter fullscreen mode Exit fullscreen mode int -> 4 byte.float ->…
Read More
Windows Powershall Commands

Windows Powershall Commands

Terminal oynasiga kirish uchun "Windows + r" klavishlarini bosib, chap pastki burchakda chiqgan oynaga "cmd" yozilsa terminal oynasiga kiriladi. "cd desktop" yozib terminal ish stoliga o'tiriladi. "mkdir_yaratmoqchi bo'lgan fayl nomi" yozilsa shu nomli fayl yaratib beradi. 3."cd_yaratilgan_fayl_nomi" yozilsa o'sha faylni ichiga kiradi. 4."cls" - "clear" vazifasini bajarib beradi ya'ni tepada yozilgan hamma narsani tozalab beradi. 5."dir" bilan sizda nechta fayl borligini va falyllar ichida nima borligini chiqazib beradi. 6."dotnet new" yozib dotnetda nima vazifalarni qila olishimizni chiqarib beradi. 7."dotnet new console" yozib yangi console loyiha yaratib olsa bo'ladi. 8."dotnet new console -n yaratmoqchi_bo'lgan_papka_nomi" yozilsa shunday nomli papkani o'zi yaratib beradi.…
Read More
No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.