Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

ASP.

NET Core

Class Library:- A class library is a collection of reusable classes, interfaces, and


other types that can be used in various applications. It is a way to organize and
distribute code so that it can be easily shared and reused across different projects.
Class libraries play a crucial role in promoting code reusability, maintainability,
and modularity in .NET.

ApplicationDbContext:-ApplicationDbContext class is often associated with


Entity Framework, a popular Object-Relational Mapping (ORM) framework used
for database interactions. ApplicationDbContext is a class that inherits from
DbContext, which is a part of Entity Framework.

Appsettings.json:- appsettings.json is a configuration file commonly used in


ASP.NET Core applications to store configuration settings and parameters. It is a
JSON-formatted file that provides a convenient way to externalize configuration
from your code. By using appsettings.json, you can change configuration values
without modifying the application code, making it easier to configure and manage
your application in different environments.

Program.cs:-ASP.NET Core application, the Program.cs file is the entry point


for the application. It contains the Main method, which is responsible for
configuring and starting the application. Here is a basic structure of a Program.cs
file in an ASP.NET Core application:

Generic Repository:- Repository is a design pattern that provides an


abstraction layer between the application's business logic and the data access code
for interacting with a data store (such as a database). The repository pattern is often
used to centralize data access logic and promote separation of concerns.

In the context of .NET applications, including ASP.NET applications, a repository


is commonly associated with Entity Framework and databases. Here's a brief
overview of how the repository pattern is typically implemented in .NET:
Non-Generic Repository:-The Non-Generic Repository Design Pattern in C#
is used to define the database operations which are related to a specific entity in a
separate class. For example, if you have two entities let’s say, Employee and
Customer, then each entity will have its own implementation Repository.

Models:- .NET development, the term "Models" typically refers to classes that
represent the data structure of your application. Models are used to define the
shape and behavior of your data entities, and they are commonly used in
conjunction with various frameworks and libraries, such as Entity Framework in
the case of database models or ASP.NET MVC for defining the structure of data
exchanged between the client and server.

ViewModels:- ViewModel is a class that represents the data and behavior


needed for a specific view. ViewModels are used to shape and organize data
specifically for presentation purposes, providing a way to bundle together data
from different models or adjust the structure of the data to match the requirements
of a particular view.

Utility:- typically refers to a class or set of classes that provide general-purpose,


often reusable, functionality that doesn't fit neatly into a specific domain or
business logic. Utilities are commonly used to encapsulate common tasks, helper
functions, or functionalities that are used across different parts of an application.

ASP.NET Web API

Data Transfer Object:- A Data Transfer Object (DTO) is a design pattern used
to encapsulate and transfer data between different layers or components of a
software application. DTOs are simple, lightweight, and contain only the necessary
data fields required for a specific operation or communication between different
parts of an application. They serve as a container for data, allowing us to transport
information between various parts of our application without exposing the
underlying implementation details.
Why Use DTOs?
Reduced Overhead: DTOs allow us to send only the data needed for a particular
task, minimizing the amount of data transmitted over the network or passed
between application layers. This reduces the overhead associated with unnecessary
data transfer.

Data Transformation: DTOs provide a structured way to transform data from one
format to another, which is particularly useful when dealing with data received
from external sources or APIs.

Enhanced Security: By limiting the data exposed to external components or


layers, DTOs can help improve security by preventing sensitive information from
being inadvertently exposed.

Performance Optimization: When working with large datasets, DTOs allow us to


select and transmit only the necessary data fields, resulting in improved
performance and reduced latency.

DTO Mapping:- DTO (Data Transfer Object) mapping in the context of an API
involves the conversion between domain models or entities and DTOs. This
mapping is necessary when you want to expose a different structure of data through
your API than what is used internally in your application. AutoMapper is a popular
library in the .NET ecosystem that simplifies the process of mapping between
objects.
DataBase
SQL=>
Structured Query Language (SQL) is a standard programming language
for managing and manipulating relational databases. It primary consists
of a set of commands for performing various operations such as
querying data, updating data, inserting data, and deleting data from a
database.

SELECT: Retrieves data from one or more tables. The basic syntax is:
SELECT column1, column2, ...
FROM table_name
WHERE condition;

INSERT: Adds new records to a table. The basic syntax is:

INSERT INTO table_name (column1, column2, ...)


VALUES (value1, value2, ...);

UPDATE: Modifies existing records in a table. The basic syntax is:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

DELETE: Removes records from a table. The basic syntax is:

DELETE FROM table_name


WHERE condition;

CREATE TABLE: Creates a new table. The basic syntax is:

CREATE TABLE table_name (


column1 datatype,
column2 datatype,
...
);

ALTER TABLE: Modifies an existing table (e.g., add or delete


columns). The basic syntax is:

ALTER TABLE table_name


ADD column_name datatype;

DROP TABLE: Deletes an existing table and its data.

DROP TABLE table_name;

JOIN: Combines rows from two or more tables based on a related


column between them. There are different types of joins, including
INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.

SELECT columns
FROM table1
JOIN table2 ON table1.column = table2.column;

GROUP BY: Groups rows that have the same values in specified
columns into summary rows, like "total" or "average."

SELECT column1, COUNT(*)


FROM table_name
GROUP BY column1;
ORDER BY: Sorts the result set of a query in ascending or descending
order based on one or more columns.
SELECT column1, column2
FROM table_name
ORDER BY column1 DESC;
These are just some of the basic SQL commands. SQL is a powerful
language with various capabilities for handling and managing relational
databases.

Stored Procedure
A stored procedure is a precompiled collection of one or more SQL
statements that are stored on the database server. It is a named and saved
collection of SQL statements and procedural logic that can be reused and
shared by multiple programs or users. Stored procedures offer several
advantages, including improved performance, security, and code
reusability.

Here's a basic example of creating a stored procedure:

CREATE PROCEDURE GetCustomerDetails


@CustomerID INT
AS
BEGIN
SELECT *
FROM Customers
WHERE CustomerID = @CustomerID;
END;

In this example:

GetCustomerDetails is the name of the stored procedure.


@CustomerID is a parameter that the stored procedure expects.
The AS keyword begins the body of the stored procedure.
Inside the body, there is a SQL query that retrieves customer details
based on the provided CustomerID.
You can then execute this stored procedure with the following:
EXEC GetCustomerDetails @CustomerID = 123;
Stored procedures can have input parameters, output parameters, and
even return values. They are compiled and stored in the database,
reducing the need to send the entire query from the application to the
database server each time it is executed.

Here's an example of a stored procedure with input and output


parameters:

CREATE PROCEDURE CalculateSumAndProduct


@Num1 INT,
@Num2 INT,
@Sum INT OUT,
@Product INT OUT
AS
BEGIN
SET @Sum = @Num1 + @Num2;
SET @Product = @Num1 * @Num2;
END;

In this example, @Num1 and @Num2 are input parameters, and @Sum
and @Product are output parameters. You can execute this stored
procedure and retrieve the results:

DECLARE @ResultSum INT;


DECLARE @ResultProduct INT;
EXEC CalculateSumAndProduct
@Num1 = 5,
@Num2 = 3,
@Sum = @ResultSum OUTPUT,
@Product = @ResultProduct OUTPUT;
PRINT 'Sum: ' + CAST(@ResultSum AS NVARCHAR(10));
PRINT 'Product: ' + CAST(@ResultProduct AS NVARCHAR(10));

Stored procedures provide a way to encapsulate business logic on the


database server, reducing network traffic and improving overall system
performance. They are commonly used in database management systems
like Microsoft SQL Server, MySQL, Oracle, and others.

Entity Framework:- Entity Framework (EF) is an object-relational mapping


(ORM) framework developed by Microsoft for .NET applications. It provides a set
of tools and libraries that enable developers to work with relational databases using
.NET objects. The main goal of Entity Framework is to simplify the process of
database interaction by allowing developers to work with database entities as if
they were regular .NET objects.

Entity Data Model (EDM): The Entity Data Model is a conceptual model that
represents the structure of data in a database. It includes entities, relationships, and
mapping information between the conceptual model and the actual database
schema.

DbContext: DbContext is a high-level API that acts as a bridge between the


domain or business objects in your application and the underlying database. It
manages the connection, caching, and tracking changes of entities.

Code-First and Database-First Approaches:

Code-First: Developers can define the entity classes in code, and EF will generate
the database schema based on these classes.

Database-First: Developers can start with an existing database, and EF will


generate the entity classes and context based on the database schema.

Automatic Change Tracking: EF keeps track of changes made to entities, making


it easier to update the database with modified data.
Database Providers: Entity Framework supports various database providers,
including SQL Server, MySQL, PostgreSQL, and others.

Migrations: EF provides a migration feature that enables developers to evolve the


database schema over time as the application's data model changes.

Entity Framework Core: Entity Framework has evolved, and there is also a
lightweight and cross-platform version called Entity Framework Core, which is
designed to work with .NET Core and .NET 5 and later.

JWT:- JWT stands for JSON Web Token. It is a compact, URL-safe means of
representing claims to be transferred between two parties. These claims are
typically used to identify the user and provide additional information about them.
JWTs can be digitally signed, providing a way to verify the integrity and
authenticity of the information they contain.

You might also like