Posts

Showing posts from March, 2023

ASP.NET Core 6: Creating API for CRUD Operations using EntityFrameworkCore (Basic for new ASP.NET Core Learners): Part 2

Image
In Part 1 , we have gone through the basic understanding of creating an ASP.NET Core Web API project. In this part, we will see how we can use EntityFramework Core (EF Core) to build Data Access Layer and create WEB API.  EntityFramework Core The EntityFramework Core is a cross-platform Object Relational Mapping (ORM). This provides an object model that manages database connections and mapping with tables of the database. The DbContext class provided in EF Core is used to manage database connections and performs commit transactions. The DbSet<T> generic in EF Core represent the entity class aka CLR Object mapping with a table of the database. Here we can say that  T is an entity class mapped with the table of a database named T.  The EF Core provides the following two approaches: Database First: The Entities and DataAccess layer is created based on the ready-to-use database Code-First: The Database and its tables are created using entities we create in the project    We can use E

ASP.NET Core 6: Creating API for CRUD Operations using EntityFrameworkCore (Basic for new ASP.NET Core Learners): Part 1

Image
In this article, we will go through the steps for creating ASP.NET Core API. We use API aka REST  APIs for creating data communication services. In short, we can say that we are building a service that can be consumed (or subscribed to) by any client application e.g.  JAVA, .NET, JavaScript Clients (like React, Angular, and Vue.js) so that these applications can make HTTP Requests and perform Data communication in JSON form. We can say the APIs can establish a data communication bridge between homogeneous or heterogeneous applications.    The ASP.NET Core is a complete eco-system that provides a single HTTP Pipeline for the following applications ASP.NET Core Razor Application ASP.NET Core MVC Application ASP.NET Core  Web API Application In this step-by-step post, we will use Visual Studio 2022 for creating the ASP.NET Core API project and SQL Server 2018 for the database.  The database scripts are provided in Listing 1. Create Database Company GO CREATE TABLE [dbo].[Department]( [

ASP.NET Core 7: Uploading files using Minimal APIs

Image
The minimal APIs in ASP.NET Core 7 is one of the best features. I have already written a post on the minimal APIs. In this article, I will demonstrate an approach to uploading files using minimal APIs. I have already written a post on file upload using ASP.NET Core on this link .   Step 1: Open Visual Studio 2022 and create a new ASP.NET Core API project targeted to .NET 7. Name this project  Core7_FIleUpload_MinimalAPI. You need to make sure that, the checkbox Use controllers (uncheck to use minimal APIs) is unchecked as shown in Figure 1. Once we uncheck this checkbox, then we will not see the  Controllers folder in our project. We need to write the API login in Program.cs. In this project add a new folder and name it files. All uploaded files will be stored in this folder.  Step 2: In the Program.cs, we will create two APIs one each for uploading a single file and uploading multiple files. To upload a single file we use the IFromFile interface. This interface represents a file sent

ASP.NET Core 7: Using PostgreSQL to store Identity Information

Image
In this article, we will see using the PostgreSQL database to store the ASP.NET Identity information in it. If the ASP.NET Core application is using PostgreSQL database instead of SQL Server database then we can use it to store application user and role information. This article is a simple implementation of identity in ASP.NET Core using PostgreSQL. To create a database and tables for storing ASP.NET Identity information, we use classes like IdentityUser, IdentityRole, etc. The EntityFrameworkCore Code-First approach is used to create a database and tables.  Step 1: Open Visual Studio 2022 and create a new ASP.NET Core API project. Name this project as Core_API_Postgre_Identity. To use Identity classes and PostgreSQL add the following packages to the project Microsoft.AspNetCore.Identity This package is needed to use IdentityUser and IdentityRole classes Microsoft.AspNetCore.Identity.EntityFrameworkCore This package is needed to use IdentityDbContext class. This class is used as a bas