Posts

Showing posts from October, 2022

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....

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...

ASP.NET Core 6: The Minimal APIs

Image
In this article, we will the implementation of Minimal APIs. As we all know that we have WEB APIs provided on .NET Framework and then ASP.NET Core eco-systems. But one common thing for the API implementation is that all these were implemented as Controller APIs, We need to create a Controller class that has the  ApiController attribute applied and this is derived from the ControllerBase class. Once the controller is added, we add the HTTP Action method in it so that these will be executed based on HTTP requests. Although the approach of creating a controller class is great e.g. in the case of security, versioning, etc. But what if we need simple APIs e.g. creating Microservices in a simpler way. In this case, the API code must be easy and focused on the needs. The Minimal APIs provided in ASP.NET Core 6 are the best approach.  The overall idea of creating Minimal API is that they avoid the code of creating a Controller class instead the HTTP requests are directly mapped with t...