Posts

Implementing Distributed Caching in ASP.NET Core 6 using the Redis Cache In Microsoft Azure

Image
In this article, we will implement distributed caching for ASP.NET Core 6 applications using Redis Cache in Microsoft Azure. In highly responsive web applications as well as in Microservices applications caching plays a very important role. We use caching to store data so that it can be made available to the application at a fast speed when it is required. In ASP.NET Core, we can have caching implemented using In-Memory Cache and Distributed Cache. The Caching Concept A Cache is a mechanism using which the frequently demanded data is stored for a specific duration. Typically, the data required for searching can be stored in the cache and hence this helps to reduce the number of calls to the actual database. Since the data is immediately available to the application, the number of resource requirements e.g. waiting time for the Db Connections can be reduced and hence this results in the performance increase of the application.  The question is what type of data can be stored in the cach

Implementing Server-Side Pagination using ASP.NET Core API and React.js 3

Image
In this article, we will perform server-side pagination using ASP.NET Core API, Entity Framework Core, and the React.js front-end. We should choose the option of server-side pagination when the server returns a large amount of data. The pagination makes sure that the front end is provided with a limited set of data so that the response to the client application is as lightweight as possible. To implement the code for this article I have used the Northwind database. Scrips for the Northwind can be downloaded from this link .    Figure 1 will provide an idea of the implementation   Figure 1: The Application Implementation    For fetching a specific number of records from the table, we can use LINQ with Skip() and Take() methods. I have used the LINQ with Entity Framework Core to implement the server-side pagination.   Once the Northwind database is created, we can see various tables in it. Some of the tables contain Null values. So I have used the query as shown in Listing 1 to create a

Uploading Excel File to ASP.NET Core 6 application to save data from Excel to SQL Server Database

Image
Recently, while conducting a session on ASP.NET Core 6, my client raised a query regarding uploading excel files to the ASP.NET Core MVC application and then further saving data from excel to the SQL Server Database table. I gave him the solution and then thought to write a post on it. As we all know, the Excel Workbook is one of the most heavily used files to save data. But to persist data it is recommended that it should be stored in an SQL Server database.  If the data is stored in an SQL Server database it can be queried easily.  Figure 1, explains an implementation of the application which we are going to discuss in the article. Figure 1: The ASP.NET Core That accepts Excel files and then further store data from Excel Files in SQL Server Database The   ExcelDataReader.DataSet Library To read excel files in ASP.NET Core applications, we need to use the ExcelDataReader.DataSet package. This is a lightweight and fast library for reading Excel files in .NET applications. This is writt

ASP.NET Core 6 API: How to use Dapper With ASP.NET Core API

Image
In this article, we will see an implementation of using Dapper in ASP.NET Core API for working with data access to perform CRUD operations.  What is Dapper? Dapper is a popular simple object mapping tool. It is Object Relational Mapping (ORM).  Practically this falls into the category of the micro-ORM.   We use Dapper in our application to communicate with the database to perform CRUD operations. The Dapper has huge performance benefits because it does not translate queries written in .NET to SQL. One of the recommended practices is that the parameterized queries are supported by Dapper which helps to avoid SQL injections and we must always follow this as a practice. Technically, Dapper extends  IDbConnection so that it can support multiple database providers. There are the following useful extension methods  Query : The extension method that is used to execute the query and map result. QueryFirst : This method is used to execute the query and map the first result. QueryFirstOrDefault