Posts

Showing posts from March, 2025

Advanced Dapper Usage in .NET Core

Advanced Dapper Usage in .NET Core Dapper is a micro-ORM that provides powerful database interaction capabilities in .NET Core applications. In this article, we’ll explore advanced techniques, including executing stored procedures, handling multiple result sets, and building dynamic queries.   Executing Stored Procedures with Dapper Dapper makes it easy to execute stored procedures and map results to C# objects. Example: Calling a Stored Procedure Assume we have a stored procedure GetEmployeeById that retrieves employee details: CREATE PROCEDURE GetEmployeeById     @Id INT AS BEGIN     SELECT * FROM Employees WHERE Id = @Id; END; Using Dapper to Call the Stored Procedure using (var connection = new SqlConnection(_connectionString)) {     var employee = connection.QuerySingleOrDefault<Employee>(         "GetEmployeeById", new { Id = 1 }, commandType: CommandType.St...

Implementing Single Sign-On (SSO) in .NET Core and Angular

Implementing Single Sign-On (SSO) in .NET Core and Angular Introduction Single Sign-On (SSO) is a powerful authentication mechanism that enhances user experience and security by allowing users to log in once and access multiple applications without re-entering credentials. In this blog, we will walk through the implementation of SSO using OAuth 2.0 and OpenID Connect (OIDC) with IdentityServer4 in .NET Core and Angular. Why Use SSO? Improved User Experience : Users authenticate once and access multiple services without repeated logins. Centralized Authentication : Easier user management and security enforcement. Better Security : Reduces password fatigue and encourages strong authentication policies. Scalability : Works well across multiple applications, making it ideal for enterprise solutions. Step 1: Setting Up IdentityServer4 in .NET Core IdentityServer4 is an open-source framework that enables authentication and authorization using OpenID Connect and OAuth2. 1.1 Cr...

Getting Started with Dapper in .NET Core

Getting Started with Dapper in .NET Core Dapper is a  lightweight and high-performance micro-ORM  (Object Relational Mapper) for .NET that enables efficient database interactions. It is ideal for applications that prioritize speed and minimal overhead, offering a streamlined alternative to Entity Framework. This guide provides a comprehensive approach to integrating Dapper into your .NET Core projects.   1. Installing Dapper To install Dapper, use the following command in your terminal or command prompt: dotnet add package Dapper Alternatively, you can install it via the  NuGet Package Manager  in Visual Studio.   2. Setting Up Database Connection We'll use  SQL Server  for this example. Configure Connection String Add your database connection string to appsettings.json: {   "ConnectionStrings": {     "DefaultConnection": "Server=YOUR_SERVER;Database=YOUR_DB;User Id=YOUR_USER;Password=YOUR_PASSW...

Execution Plans in SQL Server: A Comprehensive Guide

Execution Plans in SQL Server: A Comprehensive Guide Introduction In SQL Server, query performance is crucial for maintaining a high-performing database. The Execution Plan is a key tool that helps developers and database administrators (DBAs) analyze how SQL Server executes queries. Understanding execution plans allows you to optimize queries, identify bottlenecks, and improve overall database efficiency. This article explores execution plans, how they work, and how you can use them to optimize your SQL queries. What is an Execution Plan? An Execution Plan is a roadmap that SQL Server generates to determine the most efficient way to execute a query. It shows the sequence of operations (such as scans, joins, sorts, and aggregations) that SQL Server uses to retrieve or modify data. Why Are Execution Plans Important? Helps diagnose slow queries. Shows how SQL Server processes queries. Identifies missing indexes or inefficient joins. Helps in performance tuning an...

Why is a Stored Procedure Precompiled in SQL Server

Why is a Stored Procedure Precompiled in SQL Server? Introduction In SQL Server, Stored Procedures are often described as "precompiled." But what does this mean, and why is it beneficial? This article breaks down the concept of precompilation in stored procedures, how it works, and why it improves performance.   What Does "Precompiled" Mean in Stored Procedures? When a stored procedure is created, SQL Server does not execute it immediately. Instead, it analyzes, parses, and optimizes the SQL statements inside the procedure, creating an execution plan. This process is called precompilation . When the stored procedure is later executed, SQL Server reuses the precompiled execution plan rather than interpreting the SQL from scratch. This reduces processing overhead and improves performance .   How Precompilation Works Step 1: Parsing and Syntax Checking When you create a stored procedure, SQL Server first parses the SQL statements to check for s...

Stored Procedure vs. Trigger in SQL Server

Stored Procedure vs. Trigger in SQL Server Introduction When working with SQL Server, two essential tools for handling database operations are Stored Procedures and Triggers . While both help automate tasks, they serve different purposes. This article breaks down their differences with clear explanations and practical examples.   What is a Stored Procedure? A Stored Procedure is a precompiled SQL script that executes on demand, allowing users to encapsulate complex SQL logic for better performance and reusability. Key Features of Stored Procedures: Manually executed using EXEC or EXECUTE commands. Can return output values or result sets. Supports parameters for dynamic execution. Explicitly handles transactions (BEGIN TRANSACTION, COMMIT, ROLLBACK). Works independently of tables, making it reusable across different queries. Example: Stored Procedure to Retrieve Orders by Customer CREATE PROCEDURE GetCustomerOrders     @CustomerID INT AS ...