Showing posts with label ASP.NET Core. Show all posts
Showing posts with label ASP.NET Core. Show all posts

Sunday, December 6, 2020

CRUD Operation In ASP. Net Core Web API with Entity Framework Core

This article will explain how to perform CRUD (Create, Read, Update, Delete) operations in Asp.Net Core Web API using Entity Framework Core. We will see step by step instructions about CRUD operations in Asp.Net Core Web API. In this demonstration, we will use the Database First Approach where our database will be ready before creating an actual code.

Create the Database and Tables
Create Asp.Net Core Web API Project
Install Nuget Packages for Entity Framework
Generates Model Classes
Setup Dependency Injection
Create Repository and implement CRUD operations
Create a Controller and Create API call
Test the API End Points in Postman
Enable CORS


Steps - 1 Create Database 
   
tables 

Step - 2 Project - asp.net core 

  setup connection string and install some dll from nuget package 
   
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer.Design
Microsoft.EntityFrameworkCore.SqlServer

after adding this 






Sunday, November 29, 2020

.net core history

 .NET Core 1.0, announced on November 12, 2014,[5] was released on June 27, 2016,[6] along with Microsoft Visual Studio 2015 Update 3, which enables .NET Core development.[7] .NET Core 1.0.4 and .NET Core 1.1.1 were released along with .NET Core Tools 1.0 and Visual Studio 2017 on March 7, 2017.[8]

.NET Core 2.0 was released on August 14, 2017, along with Visual Studio 2017 15.3, ASP.NET Core 2.0, and Entity Framework Core 2.0.[9] .NET Core 2.1 was released on May 30, 2018.[10] NET Core 2.2 was released on December 4, 2018.[11]

.NET Core 3 was announced on May 7, 2019, at Microsoft Build. Version 3.0.0 was released on September 23, 2019.[12] With .NET Core 3, the framework supports development of desktop application softwareartificial intelligence/machine learning and IoT apps.[13][failed verification]

The next release after .NET Core 3.1 is .NET 5. The .NET Framework will not receive any further major versions, and .NET 5 will be the only .NET meant for new applications going forward – hence the removal of the "Core" branding and skipping of version 4 to avoid confusion with the .NET Framework 4.x.[14] The first preview of .NET 5 was released on March 16, 2020.[15]




Wednesday, August 5, 2020

WEB API - Interview Questions and Answers . ?

How do I use exception filter in WEB API.?
How can you handle errors in WEB API.?
What are API errors?
How do I debug WebAPI.?
What is APU server error.?
How do I get a 500 error page.?
What is a 500 response code.?
What does error code 401 mean.?
How do you fix a 401 error.?
How do I get a 401 error.?
How do I create a 401 error.?
How do you fix 401 unauthorized error in Postman.?
What is 401 Authorisation required.?
What is 404 HTML.?
Why is 404 the error code.?
How do I get a 404 erro page.?
How do I fix Error 404.?
What is a 504 error.?
What does 403 Forbidden mean.?

Sunday, August 2, 2020

Recent questions asking in interview - C# , asp.net , asp.net mvc , asp.net core , sql , entity framework

 Q. Sql Injection 
 Q. Sql cache 
 Q. Exception Filter purpose
Q. MVC Validations - Jquery ka use yaha par 
Q. Await Async




1. What is the difference between SingleOrDefault and FirstOrDefault?

LINQ provides element operators that return a single element or a specific element from a collection. The elements operators are Single, SingleOrDefault, First, FirstOrDefault, Last, LastOrDefault.

Single

It returns a single specific element from a collection of elements if element match found. An exception is thrown, if none or more than one match found for that element in the collection.
SingleOrDefault

It returns a single specific element from a collection of elements if element match found. An exception is thrown, if more than one match found for that element in the collection. A default value is returned, if no match is found for that element in the collection.

First

It returns first specific element from a collection of elements if one or more than one match found for that element. An exception is thrown, if no match is found for that element in the collection.

FirstOrDefault

It returns first specific element from a collection of elements if one or more than one match found for that element. A default value is returned, if no match is found for that element in the collection.

When to use Single, SingleOrDefault, First and FirstOrDefault

You should take care of following points while choosing Single, SingleOrDefault, First and 
FirstOrDefault:
When you want an exception to be thrown if the result set contains many records, use Single or SingleOrDefault.
When you want a default value is returned if the result set contains no record, use SingleOrDefault.
When you always want one record no matter what the result set contains, use First or FirstOrDefault.
When you want a default value if the result set contains no record, use FirstOrDefault.

Perfomance of SingleOrDefault and FirstOrDefault

FirstOrDefault usually performs faster as compared to SingleOrDefault, since these iterate the collection until they find the first match. While SingleOrDefault iterates the whole collection to find one single match.

Q.2 AllowAnonymous Attribut and Authorize Attribute.?

One of the new features in ASP.NET MVC 4 is the AllowAnonymous Attribute that helps you secure an entire ASP.NET MVC 4 Website or Controller while providing a convenient means of allowing anonymous users access to certain controller actions, like the login and register Actions.


AllowAnonymous Attribute in ASP.NET MVC 4

As mentioned, if you create a new ASP.NET MVC 4 Internet Project in Visual Studio 2010 or Visual Studio 11 and view the AccountController you will notice the generous use of the AllowAnonymous Attribute on various login and register controller actions. Here are a few of those controller actions.

[Authorize] 
public class AccountController : Controller 
 [AllowAnonymous] 
 public ActionResult Login() 
 // ... 
 } 
 [AllowAnonymous]
 [HttpPost] 
 public JsonResult JsonLogin(LoginModel model, string returnUrl) 
 // ...
 }
 [AllowAnonymous]
 [HttpPost] 
 public ActionResult Login(LoginModel model, string returnUrl) 
 // ... 
 }
 [AllowAnonymous] public ActionResult Register() 
 // ... 
 } 
 [AllowAnonymous] 
 [HttpPost] 
 public ActionResult JsonRegister(RegisterModel model)
 {
 // ... 
 }
 [AllowAnonymous]
 [HttpPost] 
 public ActionResult Register(RegisterModel model) 
 // ... 
 } 
}

The idea is pretty simple. The Authorize Attribute on the AccountController in this ASP.NET MVC 4 Application denies anonymous access to every controller action. However, we need to allow anonymous access to the login and register controller actions so we decorate them with the AllowAnonymous Attribute which negates the Authorize Attribute and allows anonymous access.

Q.3 What is mvc Filters and custom filters . ?


ASP.NET MVC provides Action Filters for executing filtering logic either before or after an action method is called. Action Filters are custom attributes that provide declarative means to add pre-action and post-action behavior to the controller's action methods.

Q.4 What is Dependency injection with examples . ?

In software engineering, dependency injection is a technique in which an object receives other objects that it depends on. These other objects are called dependencies. In the typical "using" relationship the receiving object is called a client and the passed object is called a service.


What is Startup.cs File in asp.net core

Rewrite whole Web Site System and Sub System with data migration to new system.

Can you please share me your skype id or whats up number for better communications  my skype id is - jitendra.tech  whats up - +919617741414...