Code
C# Classes

In C#, classes are foundational to object-oriented programming (OOP). They encapsulate data for the object and methods to manipulate that data. Along with class structures, there are other constructs like interfaces and abstract classes which help in defining contracts, encapsulating functionality, and providing a blueprint for objects.

Example classes

Overloading and Overriding in C#

Method overloading and overriding are fundamental features in C#'s support for polymorphism. They help achieve both compile-time and run-time polymorphism.

In C#, method overloading allows a class to have multiple methods with the same name but with a different parameter list.

Overriding, on the other hand, is when a derived class provides a specific implementation for a method that is already defined in its base class or one of its base classes. The method in the derived class should have the same name, return type, and parameters as the method in the base class.

Examples Overloading and Overriding

Testing Minimal APIs

With .http files in Visual Studio 2022, ASP.NET Core's minimal APIs are an excellent tool for quickly and succinctly defining web APIs.

Read more...

Microsoft Content

Microsoft Learn http file tests

SOLID Principles

SOLID stands for five principles that help in designing software architecture that is easy to manage and maintain:

  • Single Responsibility Principle (SRP)
  • Open Closed Principle (OCP)
  • Liskov Substitution Principle (LSP)
  • Interface Segregation Principle (ISP)
  • Dependency Inversion Principle (DIP)
DRY Principle

DRY stands for "Don't Repeat Yourself". The DRY principle is a best practice in software development that recommends developers to avoid writing duplicate code. This can be achieved by abstraction, encapsulation, inheritance, and others.

Mapperly

Use Mapperly to map your objects. Mapperly

dotnet add package Riok.Mapperly --version 1.0.0
YouTube

Advanced C# Programming Course C# Advance YouTube

React

React is a JavaScript library developed by Facebook for building user interfaces. It allows developers to create reusable UI components and manage state efficiently, leading to dynamic and interactive web apps.

React Hooks

React prevState / prevProps

Next.js

Next.js is a leading framework built on React that enables server-side rendering, static site generation, and routing capabilities to produce optimized and scalable web applications.

Next.js 13 Notes

Vite in Action: A Case Study

The project showcased here serves as a practical example of a web application built using a robust technology stack featuring React, Vite, and TypeScript. Vite is a modern build tool engineered to offer a streamlined and efficient development experience for contemporary web applications. The project uses a C# Minimal API backend to serve the React frontend. There is a JWT authentication system in place to protect the API endpoints. The tool is segmented into two main components:

  • Development: Provides an exceptionally fast development environment with features like Hot Module Replacement (HMR).
  • Production: Optimizes your project for a production environment with a minimal and efficient output.

Explore Live Example: Visit AI Art Collector

API with Python

A simple API built using FastAPI that interacts with a SQLite database to retrieve and filter person records based on age and gender. It provides three different endpoints: one that returns the data in JSON format, one that returns the data in HTML format, and a default root endpoint that confirms the API is working successfully.

FastAPIwithDBcallsExample

Python Tricks

Welcome to the LearnPython.org interactive Python tutorial.

Read more...
SQL Fundamentals
MERGE

The `MERGE` statement, often referred to as an "upsert", allows you to insert, update, or delete records in one table based on the source data from another table.

MERGE example

UNION and UNION ALL

`UNION` is used to combine the result sets of two or more SELECT statements. It removes duplicate rows. `UNION ALL` does the same, but it doesn't remove duplicate rows.

UNION and UNION ALL examples

User Defined Functions (UDF)

UDFs allow you to define your own T-SQL functions that can accept 0 or more parameters and return a single scalar data value or a table data type.

UDF example

Stored Procedure with Transaction and Error Handling

Stored procedures in SQL Server are precompiled collections of one or more SQL statements. They offer the ability to encapsulate logic, can accept parameters, and return results. A key benefit of stored procedures is their capability to integrate robust error handling and transactions. Transactions ensure that a series of operations are treated as a single unit, with an all-or-none execution guarantee. They are controlled by BEGIN TRANSACTION, COMMIT, and ROLLBACK commands, safeguarding data integrity. Moreover, the TRY-CATCH construct in SQL Server further enhances error management within stored procedures. If any error arises in the TRY block, control diverts to the corresponding CATCH block, enabling precise error handling procedures, such as logging or resource cleanup.

Stored Procedure with Transaction example

Joins

SQL Joins are used to retrieve data from multiple tables based on logical relationships between them. There are different types of joins: INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.

Joins example

Subqueries

Subqueries are SQL queries nested inside another query. They can be used with SELECT, INSERT, UPDATE, and DELETE statements.

Subquery example

Indexes

Indexes are used to retrieve data from the database more quickly. They are similar to an index in a book and can be created on one or more columns of a table.

Indexing example

Views

A view is a virtual table based on the result-set of an SQL statement. It contains rows and columns, just like a real table, but doesn't store data physically.

Views example

Triggers

Triggers are special types of stored procedures that are automatically executed (or fired) when a specific event occurs in the database, such as INSERT, UPDATE, or DELETE operations.

Triggers example

Common Table Expressions (CTEs)

A CTE provides the means to temporarily result a dataset which can be easily referenced within a SELECT, INSERT, UPDATE or DELETE statement.

CTE example

Window Functions

Window functions operate on a set of rows and return a single aggregated value for each row. Common examples include ROW_NUMBER(), RANK(), and DENSE_RANK().

Window Functions example

Constraints

Constraints are used to specify rules for data in a table. Common constraints include PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, and CHECK.

Aggregate Functions

Aggregate functions perform a calculation on a set of values and return a single value. Common examples include COUNT(), SUM(), AVG(), MAX(), and MIN().

DBCC CHECKIDENT

The `DBCC CHECKIDENT` command is used in SQL Server to check the current identity value for a table (if it's an identity column) and can also be used to manually set a new starting value for the identity column (known as reseeding). For instance, to reset the counter of an identity column in a table named "MyTable" to start with 1, you would use the command DBCC CHECKIDENT ('MyTable', RESEED, 0);. Be cautious as reseeding can lead to duplicate values or gaps in the sequence if not managed correctly. Always backup data before performing such operations.

Normalization

Normalization is the process of efficiently organizing data in a database. The main aim is to eliminate redundancy and improve data integrity.

Test-Driven Development (TDD)

Test-Driven Development (TDD) is a methodology where developers first write failing tests for a new feature or improvement. They then write code to pass the tests and refactor for optimal standards. This "test first" approach ensures code accuracy, maintainability, and resilience.

MS Test Example: Calculator Tests

Using MSTest framework, I have developed a suite of tests for a simple calculator application. The tests cover basic arithmetic operations, and also delve into more complex scenarios, ensuring robustness of the calculator's functionalities.

CalculatorTestsExample
ASP.NET MVC Data Transfer

In the ASP.NET MVC framework, there are three primary mechanisms to pass data from the controller to the view.

ViewBag

ViewData

TempData

MVC Data Transfer Mechanisms

ASP.NET Core MVC Tag Helpers

ASP.NET Core MVC introduces Tag Helpers to render HTML dynamically. These Tag Helpers simplify the process of binding server-side content within HTML tags.

asp-for

asp-action

asp-controller

asp-route

asp-area

asp-validation-for

asp-validation-summary

MVC Tag Helpers