+91-90427 10472
         
Dot net training in Chennai

Microservices Architecture with DOTNET Core

Introduction:
The ability of microservices architecture to break down large, monolithic applications into smaller, independent services has led to widespread adoption. This article delves into the design principles and implementation strategies for developing microservices with DOTNET Core, Microsoft’s versatile and powerful framework.

Understanding Microservices Architecture:

Microservices is a design style in which an application is made up of loosely coupled, independently deployable services. Each service is intended to carry out a specific business function and communicates with other services via well-defined APIs.

Design Principles:
1. Single Responsibility Principle (SRP): Each microservice should be responsible for a single business capability. This ensures ease of use and maintainability.
2. Decentralized Data Management: Databases belong to microservices. Because of this decentralization, dependencies are reduced and each service is free to select the database technology that best meets its needs.
3. Inter-Service Communication: APIs are used by services to communicate with one another, and they frequently use lightweight protocols such as HTTP/REST or messaging queues. This allows for independence and flexibility in technology stack selection.
4. Fault Tolerance and Resilience: Create services that are resistant to failure. To handle faults gracefully, use mechanisms such as circuit breakers and retries.
5. Continuous Integration and Deployment (CI/CD): Use CI/CD techniques to automate the processes of building, testing, and deployment. This guarantees the delivery of microservices quickly and consistently.
6. Scalability: Microservices can be scaled independently based on demand. By horizontally scaling instances, you can design services to handle varying levels of load.

Implementation with DOTNET Core:
1. Service Development: For each microservice, create a separate DOTNET Core project. Build web APIs with ASP DOTNET Core and consider high-performance communication technologies like gRPC.
2. API Gateway: Set up an API Gateway to manage and route requests to the proper microservices. In Azure, tools such as Ocelot and API Gateway can be used.
3. Service Discovery: To dynamically locate and call services, use service discovery tools such as Consul or Eureka. This is critical for dealing with the fluid nature of microservices.
4. Containerization: Use Docker to containerize each microservice. This ensures consistency across environments and makes deployment easier.
5. Orchestration with Kubernetes: Use Kubernetes to orchestrate and manage containers. Kubernetes makes it easier to deploy, scale, and manage microservices.
6. Logging and Monitoring: Consolidate logging and monitoring. Tools such as the ELK stack (Elasticsearch, Logstash, Kibana) or Application Insights can provide insights into the behavior of microservices.
7. Security: Implement an all-encompassing security strategy. Utilize OAuth for authentication, JWT for token-based authorization, and HTTPS for secure communication.
8. Testing: For each microservice, perform unit testing, integration testing, and end-to-end testing. In this context, tools like xUnit, NUnit, and Postman can be useful.
9. Database Management: Select databases based on the needs of the microservices. Accept polyglot persistence and think about SQL and NoSQL databases.
10. Event-Driven Architecture: Think about using event-driven patterns with message brokers such as RabbitMQ or Apache Kafka. Asynchronous communication between microservices is enabled by events.

Conclusion:
Using DOTNET Core to build microservices necessitates adhering to architectural principles that prioritize independence, scalability, and maintainability. Developers can create a robust microservices ecosystem that meets the demands of modern, scalable applications by using a containerized and orchestrated approach. The combination of DOTNET Core and microservices unleashes the power of agile development, rapid deployment, and efficient scaling, enabling organizations to deliver resilient and scalable applications in today’s dynamic computing landscape.

 

Begin your journey today, for Training / Technical Support,

Contact via Call/WhatsApp :+91 90427 10472 

Solid Principles in C#.net

In C#, the SOLID principles are a set of guidelines that help developers design software that is modular, maintainable, and extensible. SOLID is an acronym that stands for:

S – Single Responsibility Principle (SRP)

O – Open-Closed Principle (OCP)

L – Liskov Substitution Principle (LSP)

I – Interface Segregation Principle (ISP)

D – Dependency Inversion Principle (DIP)

Single Responsibility Principle (SRP):

A class should have only one reason to change. It states that a class should have only one responsibility or job. This principle helps to keep classes focused, maintainable, and easier to understand.

public interface INotificationService
{
void SendNotification(string message);
}
public class EmailNotificationService : INotificationService
{
public void SendNotification(string message)
{
// Code to send an email notification
}
}
public class SMSNotificationService : INotificationService
{
public void SendNotification(string message)
{
// Code to send an SMS notification
}
}
public class NotificationSender
{
private readonly INotificationService _notificationService;
public NotificationSender(INotificationService notificationService) { _notificationService = notificationService; } public void SendNotification(string message) { _notificationService.SendNotification(message); }
}

In this example, the FileManager class has the responsibility of reading and saving files, while the FileParser class is responsible for parsing files. Each class has a single responsibility, making it easier to understand and maintain.

Open-Closed Principle (OCP):

Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. This principle encourages designing modules that can be extended without modifying their existing code, reducing the risk of introducing bugs and making it easier to add new features.

public abstract class Shape
{
public abstract double CalculateArea();
}
public class Rectangle : Shape
{
public double Width { get; set; }
public double Height { get; set; }
public override double CalculateArea() { return Width * Height; }
}
public class Circle : Shape
{
public double Radius { get; set; }
public override double CalculateArea() { return Math.PI * Radius * Radius; }
}

In this example, the Shape class is open for extension, as new shapes can be added by creating new subclasses of Shape. The existing code is closed for modification, as the Shape class and its existing subclasses do not need to be changed when adding new shapes.

Liskov Substitution Principle (LSP):

Objects of a superclass should be able to be replaced with objects of their subclass without breaking the behavior of the system. In other words, derived classes should be substitutable for their base classes, and they should honor the contracts defined by the base class.

public class Vehicle
{
public virtual void Start()
{
Console.WriteLine(“Starting the vehicle”);
}
}
public class Car : Vehicle
{
public override void Start()
{
Console.WriteLine(“Starting the car”);
}
}
public class Motorcycle : Vehicle
{
public override void Start()
{
Console.WriteLine(“Starting the motorcycle”);
}
}

In this example, the Car and Motorcycle classes are subclasses of Vehicle, and they can be substituted for Vehicle without breaking the behavior of the system. The Start method is overridden in each subclass, providing specific implementations for starting a car and starting a motorcycle.

Interface Segregation Principle (ISP):

Clients should not be forced to depend on interfaces they do not use. This principle encourages the creation of small, specific interfaces instead of large general-purpose interfaces. It helps to avoid forcing clients to implement methods they don’t need and promotes decoupling and flexibility.

public interface IOrder
{
void ProcessOrder();
}
public interface IShipping
{
void ShipOrder();
}
public class OnlineOrder : IOrder, IShipping
{
public void ProcessOrder()
{
Console.WriteLine(“Processing online order”);
}
public void ShipOrder() { Console.WriteLine("Shipping online order"); }
}
public class OfflineOrder : IOrder
{
public void ProcessOrder()
{
Console.WriteLine(“Processing offline order”);
}
}

In this example, we have two interfaces: IOrder and IShipping. The OnlineOrder class implements both interfaces, as it can process an order and ship it. The OfflineOrder class only implements the IOrder interface because it doesn’t involve shipping. This segregation of interfaces ensures that classes only depend on the methods they actually need.

Dependency Inversion Principle (DIP):

High-level modules should not depend on low-level modules; both should depend on abstractions. Abstractions should not depend on details; details should depend on abstractions. This principle promotes loose coupling between modules, promotes modular design, and enables easier testing and maintainability.

public interface INotificationService
{
void SendNotification(string message);
}
public class EmailNotificationService : INotificationService
{
public void SendNotification(string message)
{
// Code to send an email notification
}
}
public class SMSNotificationService : INotificationService
{
public void SendNotification(string message)
{
// Code to send an SMS notification
}
}
public class NotificationSender
{
private readonly INotificationService _notificationService;
public NotificationSender(INotificationService notificationService) { _notificationService = notificationService; } public void SendNotification(string message) { _notificationService.SendNotification(message); }
}

In this example, the NotificationSender class depends on the INotificationService interface rather than concrete implementations. This allows different notification services to be injected at runtime, promoting loose coupling. The high-level module (NotificationSender) depends on the abstraction (INotificationService) rather than the low-level modules (EmailNotificationService, SMSNotificationService).

By adhering to these principles, developers can create code that is easier to understand, maintain, and modify, leading to more robust and scalable software systems.

C# Web API

C# Web API

Asp.net Web API is a framework that is provided by Microsoft and used to create HTTP services.

ASP.NET Web API is an easy-to-build HTTP web service. To reach a range of clients, including browsers, mobile applications, desktop applications, and IOTs.

The Asp.net web API has two layers.

 1.client layer

 2.server layer

It is accessed by a wide range of clients, including web browsers, mobile applications, and desktop applications, when the client layer makes a request to the web API to get an output response in different formats like JSON or XML.

Http Request = http://servername/apiname?id=101
Http Response = {“Name”,ABC,”Age”:”54”}

What is HTTP?  
HTTP – Hyper Text Transfer Protocol means the user gets a different device to get a request, but the output gets the same response server, also called HTTP.
HTTP Is used more than providing web page and also strong foundation for the developing API.
HTTP is a essential and pervasive protocol  

Why to choose ASP.NET Web API?

  • Web API is light weight framework for API Development
  • Web API has built-in support for standard formats like JSON and XML., and Other Formats.
  • Web API is a Content Negotiation
  • c#.net Web API maps HTTP Verbs to method names

Features of Web API

Filter: It gives filters to the web application.
Action Result: It can keep the action logos client, such as information recovery.
Routing: It makes a difference in routing through different APIs.
Controller: It gives useful capabilities to the web application.
Model: It gives the basic capabilities of the web application.  

Types of Web API in C#

  1. public
  2. partner
  3. private
  4. Composite

Public APIs 

 A public API is open and available for use by outside developers or businesses; its application, Data, will develop and offer a public API. also called public APIs or external APIs.

Partner APIs

Partner APIs can interface the internal client information system with those outside groups no other APIs are allowed. APIs are generally stronger authentication, authorization, and security machines.

private APIs

Private APIs are used by enterprises to connect system and data APIs for internal use at certain security levels.

Composite APIs

Composite APIs generally combine two or more APIs’ interdependent operations. Composite APIs sometimes improve speed and performance.

C# Web API Sample Programming

Open Visual Studio 2019 > Click Create a new project > Alt+s > ASP.NET Web Application (.NET Framework) > ProjectName  ASP.NET MVC Web API

Create a new Models.cs Application Snapshot as below ,

Models Folder Right click > Add > Click Class > Reference Name Empolyee.cs

Replace the  Empolyee.cs Class with below snippet,

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;  

namespace ASP.NET_MVC_Web_API.Models
{    
public class Empolyee    
{        
public int ID { get; set; }        
public string Name { get; set; }        
public DateTime JoiningDate { get; set; }        
public int Age { get; set; }    
}
}

Controller Folder Right click > Add > Click Controller > Click  Web API

> Click Web API 2 Controller Empty> ControllerName EmpolyeeController.cs

 Create a new Controller.cs Application Snapshot as below

Replace the EmpolyeeController.cs With below Snippet ,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using ASP.NET_MVC_Web_API.Models;  

namespace ASP.NET_MVC_Web_API.Controllers
{    
public class EmpolyeeController : ApiController    
{        
Empolyee[] employees = new Empolyee[]
{            
new Empolyee            
{                
ID = 1,                
Name = “sam”,                
JoiningDate = DateTime.Parse(DateTime.Today.ToString()),                
Age = 29            
},            
new Empolyee            
{                
ID = 2,                
Name = “Balu”,                
JoiningDate = DateTime.Parse(DateTime.Today.ToString()),                 
Age = 36            
},            
new Empolyee            
{                
ID = 3,                
Name = “Michel”,                
JoiningDate = DateTime.Parse(DateTime.Today.ToString()),                
Age = 22            
}        
};        
public IEnumerable<Empolyee> GetAllEmployees()        
{            
return employees;        
}        
public IHttpActionResult GetEmployee(int id)        
{            
var employee = employees.FirstOrDefault((p) => p.ID == id);            
if (employee == null)            
{                
return NotFound();            
}            
return Ok(employee);        
}    
}
}  

Run the Application and Replace the Url

Output :

Stored Procedure in SQL Server

  • A stored procedure is a precompiled and stored database object that contains a set of SQL statements and procedural logic that can be executed as a single unit. It can be used in a database management system to simplify complex queries and database operations. It is a prepared SQL code that you can save, so the code can be reused over and over again. Stored procedures help improve performance and security, as well as simplify the code.

Here’s a basic example of a stored procedure that accepts two input parameters and returns the sum of those two numbers:

CREATE PROCEDURE AddNumbers
@n1 INT,
@n2 INT
AS
BEGIN
SET NOCOUNT ON;
SELECT @n1 + @n2 AS ‘Sum’;
END  

In this example, CREATE PROCEDURE is used to define the name of the procedure (AddNumbers) and its input parameters (@n1 and @n2). The AS keyword is used to begin the code block for the stored procedure.

SET NOCOUNT ON is used to prevent the count of the number of rows affected by the stored procedure from being returned.

The code block then calculates the sum of the two input parameters and returns the result using the SELECT statement.

Once the stored procedure is defined, it can be executed by calling its name:

EXEC AddNumbers 2, 3;

This will return the result 5 as the sum of 2 and 3.

Stored Procedure in a Basic CRUD Operation

Now, let us have an idea about using stored procedure in a basic CRUD operation sample.

Let us create a database as follows:

Create database Company

Then create a table in the corresponding database.

CREATE TABLE Employee(
EmpCode int,
EmpName nchar(100),
EmpAge int,
EmpSal int)

Inserting data into a table: This stored procedure inserts a new employee record into a table named Employee:

CREATE PROCEDURE AddEmployee
@EmpCode int,
@EmpName nchar(100),
@EmpAge int,
@EmpSal int
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO Employee(EmpCode, EmpName, EmpAge, EmpSal)
VALUES (@EmpCode, @EmpName, @EmpAge, @EmpSal);
END

On executing the above snippet, a stored procedure to add the details in the table will be created.

Now, by calling the below query, the table will get added the following 5 datas.

EXEC AddEmployee 1, ‘TOM’, 25, 30000
EXEC AddEmployee 2, ‘RAM’, 25, 30000
EXEC AddEmployee 3, ‘RAJA’, 26, 32000
EXEC AddEmployee 4, ‘SIVA’, 26, 32000
EXEC AddEmployee 5, ‘GOPI’, 25, 30000

Retrieving data from a table: This stored procedure retrieves all the rows from a table named Employee:

CREATE PROCEDURE GetEmployees
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM Employee;
END

On executing the above snippet, a stored procedure to get the employee details from the table will be created.

Then by simply calling the below query, the datas stored in the table can be retrieved.

EXEC GetEmployees

Updating data in a table: This stored procedure updates an existing employee record in a table named Employee:

CREATE PROCEDURE UpdateEmployee
@EmpCode int,
@EmpName nchar(100),
@EmpAge int,
@EmpSal int
AS
BEGIN
SET NOCOUNT ON;
UPDATE Employee SET
EmpName = @EmpName,
EmpAge = @EmpAge,
EmpSal = @EmpSal
WHERE EmpCode = @EmpCode;
END

On executing the above snippet, a stored procedure to update the details in the table will be created.

Now, by calling the below query, the data with “EmpCode =1” in the table can be updated with new data as follows.

EXEC UpdateEmployee 1, ‘Jerry’, 26, 32000

Deleting data from a table: This stored procedure deletes an existing employee record from a table named Employee:

CREATE PROCEDURE DeleteEmployee
@EmpCode int
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM Employee
WHERE EmpCode = @EmpCode;
END

On executing the above snippet, a stored procedure to delete the details in the table will be created.

Now, by calling the below query, the data with “EmpCode=1” in the table can be deleted

EXEC DeleteEmployee 1

These are just a few examples, and there are many more possibilities for what you can do with stored procedures.

OOPs Concepts

OOPs Concepts:

It is a programming paradigm that focuses on the use of objects to represent data and behaviors in software applications.

It is based on the concept of “classes” and “objects”.

The main principles of OOPs are Encapsulation, Inheritance, Polymorphism & Abstraction

Classes:
A class is a blueprint for creating objects. It defines the properties and methods that an object of that class will have. For example, a class called “Person” might have properties such as “name”, “age”, and “gender”, and methods such as “walk” and “talk”.

In C#, classes are a fundamental building block of object-oriented programming (OOP). A class is a blueprint or a template that defines the structure and behaviour of a particular type of object.

Here’s an example of a class in C#:

public class Person

{

    public string Name { get; set; }

    public int Age { get; set; }

    public string Address { get; set; }

    public void PrintDetails()

    {

        Console.WriteLine($”Name: {Name}, Age: {Age}, Address: {Address}”);

    }

}

In this example, we have defined a class called Person that has three properties: Name, Age, and Address. These properties are defined using auto-implemented properties, which are shorthand for defining a private field and public getter/setter methods.

The PrintDetails method is a behaviour of the Person class. It is a public method that can be called on an instance of the Person class to print out the person’s details.

To create an instance of the Person class and set its properties, we can do the following:

Person person = new Person();

person.Name = “John”;

person.Age = 30;

person.Address = “123 Main St.”;

And to call the PrintDetails method on the person instance:

person.PrintDetails(); // Output: Name: John, Age: 30, Address: 123 Main St.

In this way, classes in C# allow us to define the structure and behaviour of our objects and create instances of those objects with specific properties and methods.

Objects:

An object is an instance of a class. It represents a specific instance of the class and has its own set of values for the properties defined by the class. For example, an object created from the “Person” class might have a name of “John”, an age of 25, and a gender of “Male”.

In C#, an object is an instance of a class. When we create an instance of a class using the new keyword, we are creating an object of that class.

Here’s an example of creating an object of the Person class we defined earlier:

Person person = new Person();

In this example, person is an object of the Person class. We can access its properties and call its methods using the dot notation:

person.Name = “John”;

person.Age = 30;

person.Address = “123 Main St.”;

person.PrintDetails(); // Output: Name: John, Age: 30, Address: 123 Main St.

Each object of a class has its own set of properties and can have different values for those properties. For example, we can create another object of the Person class with different values for its properties:

Person person2 = new Person();

person2.Name = “Jane”;

person2.Age = 25;

person2.Address = “456 Elm St.”;

person2.PrintDetails(); // Output: Name: Jane, Age: 25, Address: 456 Elm St.

In this way, objects in C# allow us to create multiple instances of a class, each with its own set of properties and values. We can use these objects to represent real-world entities or concepts in our programs and manipulate them by calling their methods and accessing their properties.

Encapsulation:

One of the key features of OOP is encapsulation, which is the concept of bundling data and methods that operate on that data within a single unit. This makes it easier to manage and maintain the code and helps to prevent the data from being accessed or modified by code outside of the class.

Encapsulation is one of the core principles of object-oriented programming (OOP) and refers to the practice of bundling data and the methods that operate on that data within a single unit, called a class, and restricting access to the inner workings of that class from the outside world.

In C#, encapsulation is achieved through access modifiers, which are keywords that determine the level of access that other code has to a particular class member (i.e., fields, properties, methods). C# provides four access modifiers:

public: The member is accessible from any code.

private: The member is accessible only within the same class.

protected: The member is accessible within the same class and any derived classes.

internal: The member is accessible within the same assembly.

Here’s an example of using encapsulation to hide the implementation details of a Person class:

public class Person

{

    private string name;

    private int age;

    private string address;

    public string Name

    {

        get { return name; }

        set { name = value; }

    }

    public int Age

    {

        get { return age; }

        set { age = value; }

    }

    public string Address

    {

        get { return address; }

        set { address = value; }

    }

    public void PrintDetails()

    {

        Console.WriteLine($”Name: {Name}, Age: {Age}, Address: {Address}”);

    }

}

In this example, the fields name, age, and address are marked as private, which means they can only be accessed from within the Person class. However, we’ve also defined public properties Name, Age, and Address that provide access to these fields from outside the class. By using properties, we can control the access to the fields and add logic to the getter/setter methods if necessary.

The PrintDetails method is also a public method that can be called from outside the class to print out the person’s details. However, it does not provide direct access to the internal fields.

By using encapsulation in this way, we can ensure that the internal state of a class is not accidentally or intentionally modified from outside the class, and that changes to the internal implementation of the class do not affect the external code that uses it.

Inheritance:

Inheritance allows a new class to be based on an existing class, inheriting its properties and methods. This can save time and effort in development, as the new class can reuse the code of the existing class.

Inheritance is another core principle of object-oriented programming (OOP) and refers to the ability of a class to inherit properties and behaviours from a parent class. In C#, inheritance is achieved through the : symbol followed by the name of the parent class.

Here’s an example of using inheritance to create a Student class that inherits from the Person class:

public class Student : Person

{

    public int GradeLevel { get; set; }

    public string SchoolName { get; set; }

    public void PrintSchoolInfo()

    {

        Console.WriteLine($”School: {SchoolName}, Grade: {GradeLevel}”);

    }

}

In this example, the Student class inherits from the Person class using the: symbol. This means that the Student class has access to all of the public and protected members of the Person class, including its fields, properties, and methods.

In addition to the inherited members, the Student class defines two new properties, GradeLevel and SchoolName, and a new method, PrintSchoolInfo.

We can create an object of the Student class and set its properties just like we did with the Person class:

Student student = new Student();

student.Name = “John”;

student.Age = 15;

student.Address = “123 Main St.”;

student.GradeLevel = 9;

student.SchoolName = “High School”;

And we can call methods from both the Person and Student classes on the student object:

student.PrintDetails(); // Output: Name: John, Age: 15, Address: 123 Main St.

student.PrintSchoolInfo(); // Output: School: High School, Grade: 9

By using inheritance in this way, we can reuse code from existing classes and create more specialized classes that add new properties and behaviours on top of the existing ones. It also allows us to create a hierarchy of related classes, where each class builds on the properties and behaviours of the classes above it in the hierarchy.

Polymorphism:

Polymorphism allows objects of different classes to be treated as if they are of the same class, by using a common interface. This makes it easier to write code that works with multiple objects, as the code can be written to work with the interface rather than the specific classes.

Polymorphism is another core principle of object-oriented programming (OOP) and refers to the ability of objects of different classes to be used interchangeably in the same context. In C#, polymorphism is achieved through inheritance and interfaces.

There are two main types of polymorphism in C#: compile-time polymorphism and runtime polymorphism.

Compile-time polymorphism, also known as method overloading, refers to the ability of a method to have multiple definitions with different parameter lists. The correct method to call is determined at compile time based on the number and types of arguments passed to the method.

Here’s an example of method overloading in C#:

public class Calculator

{

    public int Add(int x, int y)

    {

        return x + y;

    }

    public float Add(float x, float y)

    {

        return x + y;

    }

}

In this example, the Calculator class defines two Add methods with different parameter types (int and float). Depending on the arguments passed to the Add method, the compiler will choose the appropriate overload at compile time.

Runtime polymorphism, also known as method overriding, refers to the ability of a subclass to provide a different implementation of a method that is already defined in its parent class. The correct method to call is determined at runtime based on the type of the object that the method is called on.

Here’s an example of method overriding in C#:

public class Animal

{

    public virtual void MakeSound()

    {

        Console.WriteLine(“The animal makes a sound.”);

    }

}

public class Dog : Animal

{

    public override void MakeSound()

    {

        Console.WriteLine(“The dog barks.”);

    }

}

In this example, the Animal class defines a virtual MakeSound method that can be overridden by its subclasses. The Dog class overrides the MakeSound method and provides a different implementation that prints “The dog barks.” to the console.

We can create objects of both the Animal and Dog classes and call the MakeSound method on them:

Animal animal = new Animal();

Dog dog = new Dog();

animal.MakeSound(); // Output: The animal makes a sound.

dog.MakeSound(); // Output: The dog barks.

By using polymorphism in this way, we can write code that is more flexible and adaptable to different types of objects, without having to know the exact type of the object at compile time. This makes our code more modular and easier to maintain over time.

Abstraction:

Abstraction is the concept of hiding unnecessary details and complexity from the user, while still providing the necessary functionality. This can make the code easier to use and maintain, as well as improve performance.

Abstraction is a core principle of object-oriented programming (OOP) that refers to the ability to hide the implementation details of a class from the outside world and expose only the relevant features and behaviours through a simplified interface. In C#, abstraction is achieved using abstract classes and interfaces.

An abstract class is a class that cannot be instantiated directly and can only be used as a base class for other classes. It may contain abstract methods, which are declared but not implemented in the abstract class. The subclasses of an abstract class must implement all its abstract methods to be instantiated.

Here’s an example of an abstract class in C#:

public abstract class Shape

{

    public abstract float GetArea();

}

In this example, the Shape class is declared as abstract, which means that it cannot be instantiated directly. It contains an abstract GetArea method, which is declared but not implemented in the abstract class.

Subclasses of the Shape class must provide their own implementation of the GetArea method in order to be instantiated. Here’s an example of a Rectangle class that extends the Shape class and implements the GetArea method:

public class Rectangle : Shape

{

    public float Width { get; set; }

    public float Height { get; set; }

    public override float GetArea()

    {

        return Width * Height;

    }

}

In this example, the Rectangle class extends the Shape class and provides its own implementation of the GetArea method, which calculates the area of a rectangle based on its width and height.

An interface is a contract that specifies a set of methods and properties that a class must implement. It does not contain any implementation code, but rather defines a set of public members that must be implemented by any class that implements the interface.

Here’s an example of an interface in C#:

public interface IPlayable

{

    void Play();

    void Pause();

    void Stop();

}

In this example, the IPlayable interface defines three methods (Play, Pause, and Stop) that must be implemented by any class that implements the interface.

Classes that implement the IPlayable interface must provide their own implementation of these three methods. Here’s an example of a MediaPlayer class that implements the IPlayable interface:

public class MediaPlayer : IPlayable

{

    public void Play()

    {

        Console.WriteLine(“Playing…”);

    }

    public void Pause()

    {

        Console.WriteLine(“Paused.”);

    }

    public void Stop()

    {

        Console.WriteLine(“Stopped.”);

    }

}

In this example, the MediaPlayer class implements the IPlayable interface and provides its own implementation of the Play, Pause, and Stop methods. Any class that implements the IPlayable interface can be used interchangeably with the MediaPlayer class in any context that requires an IPlayable object.

By using abstraction in this way, we can create classes that are more flexible, modular, and easier to maintain over time. We can also create a hierarchy of related classes and interfaces that define a set of common behaviours and features that can be reused and extended in different contexts.

Differences between ASP.NET Core and ASP.NET Framework

ASP.NET Core and ASP.NET Framework are both web application frameworks developed by Microsoft, but there are some significant differences between the two. Here are some of the key differences between ASP.NET Core and ASP.NET Framework:

  • Open-source and community-driven: ASP.NET Core is open-source and community-driven, with contributions from developers around the world. ASP.NET Framework is also open-source, but Microsoft is the primary contributor.
  • Cross-platform support: ASP.NET Core is designed to be cross-platform and can run on Windows, macOS, and Linux. ASP.NET Framework, on the other hand, is designed to run only on Windows.
  • Modular design: ASP.NET Core has a modular design, with a lightweight and customizable architecture that allows developers to choose only the components they need. ASP.NET Framework has a monolithic design and includes a large set of pre-built components, which can result in larger and slower applications.
  • Performance: ASP.NET Core is optimized for performance and can handle a larger number of requests per second than ASP.NET Framework. This is due to its lightweight design, which reduces overhead and allows it to run more efficiently.
  • Dependency Injection: ASP.NET Core includes built-in support for Dependency Injection, which makes it easier to manage dependencies and improve code maintainability. ASP.NET Framework does not include built-in support for Dependency Injection, although it is possible to implement it using third-party libraries.
  • Target platforms: ASP.NET Core is designed to target multiple platforms, including cloud, mobile, and desktop, while ASP.NET Framework is primarily targeted at web applications.

In summary, ASP.NET Core and ASP.NET Framework are both powerful web application frameworks, but they have some significant differences in terms of cross-platform support, open-source and community-driven development, modular design, performance, and target platforms. The choice between the two depends on the requirements of the project and the preferences of the developer.

Differences between ASP.NET Web Forms and ASP.NET MVC

ASP.NET Web Forms and ASP.NET MVC are two popular frameworks for building web applications in ASP.NET. Although both are built on the same platform and provide similar functionality, they have some key differences that set them apart. Here are some of the main differences between ASP.NET Web Forms and ASP.NET MVC:

  • Separation of Concerns: ASP.NET Web Forms allows mixing of markup (HTML) and code (C# or VB.NET) in the same file, which can make it difficult to maintain the code. ASP.NET MVC separates the markup and code into different files, which makes it easier to maintain the code.
  • Architecture: ASP.NET Web Forms uses a Page Controller architecture, where a single page contains all the code to handle the request and response. ASP.NET MVC, on the other hand, uses a Front Controller architecture, where a controller handles all the requests and responses for a group of pages.
  • Testability: ASP.NET MVC is more testable than ASP.NET Web Forms, as it separates the code and markup, making it easier to write automated tests.
  • URL Routing: ASP.NET Web Forms does not have built-in URL routing support, which can make it difficult to create search engine friendly URLs. ASP.NET MVC has built-in support for URL routing, which makes it easier to create clean and search engine friendly URLs.
  • View State: ASP.NET Web Forms uses View State to maintain the state of controls on the page. This can result in large amounts of data being sent back and forth between the server and client, which can impact the performance of the application. ASP.NET MVC does not use View State, which can improve the performance of the application.

In summary, both ASP.NET Web Forms and ASP.NET MVC are powerful frameworks for building web applications in ASP.NET. The choice between them depends on the requirements of the project and the preferences of the developer. If you need more control over the markup and want to create search engine friendly URLs, ASP.NET MVC may be the better choice. If you need a rapid application development tool and are comfortable with the Page Controller architecture, then ASP.NET Web Forms may be the better choice.

ENTITY FRAMEWORK


What is Entity Framework?
We (developers) used to frequently write ADO.NET code or Enterprise Data Access Block in Dot NET 3.5 to save or retrieve application data from the underlying database. Microsoft has provided a framework called “Entity Framework” to automate all these database-related activities for your application. Entity Framework is a Microsoft-supported open-source ORM framework for.NET applications. It enables developers to work with data using objects of domain-specific classes without focusing on the underlying database tables and columns where this data is stored.

Entity Framework in C#:
In this article, we will see how to use Entity Framework in C# applications using Visual Studio. The examples in this and likely future articles will use C# under Win Forms, but as previously stated, this choice will not affect a different intended use that the developer may reasonably request.

ORM in C#:
Optical mark recognition (also called optical mark reading or OMR) is the process of using hardware, software, or both to capture fields, for example, marks on documents such as multiple-choice questions, questionnaires with true or false fields, and other document forms.


Types of ORM Fields:

There are numerous types of OMR fields, but this section will give an overview of some of the most common ones. There can be shapes like squares, circles, and ovals.

Why Entity Framework in .NET Applications?
 Entity Framework is an ORM tool, and ORM tools are primarily used to boost developer productivity by eliminating the redundant task of performing CRUD operations against a database in a.NET application.
 Entity Framework can generate the necessary database commands for doing the database CRUD operation, i.e., can generate select, insert, update, and delete commands for us.
 While working with Entity Framework, we can perform different types of operations on the domain objects (basically classes representing database tables) using LINQ to entities.
 Entity Framework will generate and execute the SQL command in the database and then store the results in the instances of your domain objects so that you can do different types of operations on the data.

Prerequisites to Learn Entity Framework:
To fully benefit from this Entity Framework Course, you should have a basic understanding of C# as well as any database such as SQL Server, Oracle, or MySQL. It is recommended that you install the.NET Framework, Visual Studio, and SQL Server on your computer.

Advantages of Entity Framework:
Productivity:
Entity Framework can take up to 35 percent of the entire application code. It makes the developer’s life easier than ever. Despite its limitations, the designer integrated into Visual Studio dramatically simplifies the mapping process.
Maintainability:
Since you have fewer lines of code to fetch data from the database, the fewer lines of code you have to maintain.
Performance:
The complexity of ORM introduces an obvious slowdown in performance. In the entity framework first request to fetch data is a little bit slow but after that is fast to fetch data from the database.
Transactions:
ORM does all possible automation as transactions while querying the data or storing the data periodically. We can also customize transaction management practices to make the most of it out of the entity framework.

SQL Server Joins

SQL JOIN

The statement JOIN is used to combine the rows of two or more tables based  on a common column.

The different types of JOIN statement used in SQL are

  • INNER JOIN or JOIN – combines the data that matches  in both tables.
  • LEFT JOIN or LEFT OUTER JOIN – combines all the datas of left table with the datas from right table that matches.
  • RIGHT JOIN or RIGHT OUTER JOIN – combines all the datas of right table with the datas from left table that matches.
  • FULL JOIN or FULL OUTER JOIN – combines all the datas either from left or right table whenever there is a match found.

Let us consider an example:

Create a database with a name “StudentResults”

create database  StudentResults

Create a table “studentdetails” with following snippet

CREATE TABLE studentdetails (

regno int,

LastName varchar(255),

FirstName varchar(255),

age int,

dummyno int

);

Let us consider the following datas in table “studentdetails”

Create another table “result” with the snippet

CREATE TABLE result (

dummyno int,

marks int,

result varchar(10)

);

Let us consider the following datas in table “result”

 

INNER JOIN:

Inner Join is the most simplest Join. When inner join keyword is used in two tables, it will create a resulting table with combining the rows of both the tables until the condition is satisfied

For the above considered example, when inner join statement is used as follows

SELECT studentdetails.regno, studentdetails.FirstName, studentdetails.LastName, studentdetails.age, result.marks, result.result

FROM result

INNER JOIN studentdetails

ON studentdetails.dummyno=result.dummyno;

The resulting table will be

LEFT JOIN:

 Left join is also called as Left outer join. When left join keyword is used in two tables, it will create a resulting table with combining all the datas of left table with the datas from right table that matches.

For the considered example, when left join statement is used as follows

SELECT studentdetails.regno, studentdetails.FirstName, studentdetails.LastName, studentdetails.age, result.marks, result.result

FROM studentdetails

LEFT JOIN result

ON studentdetails.dummyno=result.dummyno

ORDER BY studentdetails.regno;

The resulting table will be

RIGHT JOIN:

 Right join is also called as right outer join. When right join keyword is used in two tables, it will create a resulting table with combining all the datas of right table with the datas from left table that matches.

For the considered example, when right join statement is used as follows

SELECT studentdetails.regno, studentdetails.FirstName, studentdetails.LastName, studentdetails.age, result.marks, result.result

FROM studentdetails

RIGHT JOIN result

ON studentdetails.dummyno=result.dummyno

ORDER BY studentdetails.regno;

The resulting table will be

FULL JOIN:

 Full join is also called as Outer join. When full join keyword is used in two tables, it will create a resulting table with combining all the datas either from left or right table whenever there is a match found.

For the considered example, when full join statement is used as follows

SELECT studentdetails.regno, studentdetails.FirstName, studentdetails.LastName, studentdetails.age, result.marks, result.result

FROM studentdetails

FULL OUTER JOIN result

ON studentdetails.dummyno=result.dummyno

ORDER BY studentdetails.regno;

The resulting table will be

ASP.NET Vs ASP.NET Core

ASP.NET:

ASP.NET is a basic web development tool designed and developed by Microsoft, it is used to create windows applications, websites, and web services. There are around 60 programming languages available on the ASP.NET platform, among which VB.Net and C# are mostly used.

ASP.NET Core

ASP.NET Core is a new version of ASP.NET, which was also released by Microsoft. It is a free, open source, general-purpose development tool used to develop modern cloud-based software applications on Windows or Linux or mac operating systems. It was launched as a version of ASP.NET (i. e ASP.NET 5) and later it was renamed as ASP.NET Core.

Table: difference between ASP.NET and ASP.NET Core:

ASP.NET 

ASP.NET Core

Only some components of the ASP.NET Framework are open source.

ASP.NET Core is completely a free and open-source tool.

It runs only on ASP.NET Framework.

It runs on ASP.NET Core and ASP.NET Framework.

Performance is good.

Performance is very high than ASP.NET.

ASP.NET Framework is compatible only with the Windows operating system.

ASP.NET Core is compatible with various operating systems — Windows, Linux, and Mac OS.

It Supports Web-Forms, MVC and Web API.

It supports MVC, Web API and web pages of ASP.NET Core2.0. but does not support Web-Forms.

C#, VB, and many other languages can be used.

 C# and F# languages are only supportable.

All major versions supported.

Supports Visual Studio core from version 3 to current version.

Whenever we modify or update a code, we need to re-compile the program.

Whenever we modify or update a code, the Core Browser refresh will compile and execute the program itself, So no need to re-compile it again.

It is not suitable for any mobile application development. But used for the development of both desktop and web applications.

It is not suitable for desktop application development, but suits well for development of web, windows mobile and windows store.

In case of mobile applications, it can be used on devices which work on android and windows OS, Xamarin’s tools is used to configure such mobile applications.

It is installed as a single package for Windows OS.

As it is cross-platform, it is packaged and installed individually depending on the operating system used.

ASP.NET Framework is heavy for Command Line Interface (CLI).

ASP.NET core gives a lightweight CLI.

Code access security is available for security purposes.

No such security features available.

 

Summary:
If your application

  • is to be designed to run only on Windows
  • uses only the technologies of ASP.NET framework and if it does not support the technology of ASP.NET Core
  • is already running on ASP.NET Framework

Then it is better to choose ASP.NET Framework.

 If you are

  • developing a new application and have a choice to choose between ASP.NET Core or ASP.NET Framework
  • Targeting for microservices applications
  • in need of a tool with features such as cross-platform, high performance, and scalability

Then ASP.NET Core is best choice.

 The ASP.NET Core has the following advantages in comparison to ASP.NET Framework

  • Open Source
  • Cross-Platform
  • High Performance
  • Multiple development platform
  • Multi environmental modes

 

Subquery in SQL

Query: A query is a request for data or information from one or more tables of a database.

Sub Query: In SQL language, we can place a Query inside another Query. This Query which is placed inside another query is called as subquery, also known as Nested Query

Subqueries can be used with SELECT, UPDATE, INSERT, DELETE statements along with the equality operator or comparison operator such as =, >, =, <= and Like operator.

Subquery must be enclosed in parentheses.

An ORDER BY command cannot be used in a subquery, but the main query can use an ORDER BY. The GROUP BY command can be used instead of ORDER BY in a subquery.

 

Subquery – SELECT Statement

Consider a Query

Select * from StudentDetails

When this query when executed, selects all rows of the table

Now consider an example with subquery Select

Select * from StudentDetails

where ID in (Select ID from StudentDetails where Percentage > 90);

When this set of queries gets executed,

Always the subquery gets executed first, selects the ID from StudentDetails table whose percentage is greater than 90, And then the outer query gets executed later, selecting the ID equal to the result of subquey

 

Subquery – INSERT Statement

Now consider an example with subquery Insert

Insert into StudentDetails_new

Select * from StudentDetails where ID in (Select ID from StudentDetails );

Here a new table with StudentDetails_new is created with the same structure as StudentDetails table, now to copy the datas of StudentDetails table to StudentDetails_new table , insert  statement can be used.

 

Subquery – UPDATE Statement

Now consider an example with subquery update

update StudentDetails

Set mark = mark + 5

Where mark in (Select mark from StudentDetails where mark >= 91);

Here in the table StudentDetails, the mark can be updated with a bonus of 5 marks for those who have scored mark of 91 and above using this update statement.

 

Subquery – DELETE Statement

Now consider an example with subquery delete

Delete from StudentDetails

Where mark in (Select mark from StudentDetails where mark < 50);

Here in the table StudentDetails, the datas with marks less than 50 can be removed using delete statement.

 

Free dotnet training in chennai

Following are the criteria for the selection of candidates.

  • Bright graduates who got good score (75%) from their schooling to till their graduation.
  • We offer .net training at free of cost.
  • Neccesary soft copy for documents need to be sent for evidence
  • No hidden charges applied.
  • There will be a screening interview to shortlist.

Excluding the above criteria, candidate can be considered based on financial situation. The selected candidate is expected to complete the 40 hrs training and should not discontinue.

whats app – +919042710472 to enroll yourself if you match the criteria.