LINQ Single vs SingleOrDefault vs First vs FirstOrDefault

Single(), SingleOrDefault(), First() and FirstOrDefault() are extension methods of the Enumerable class. Many people get confused about the difference between Single, SingleOrDefault, First, and FirstOrDefault methods in Linq. Let’s understand the difference between all these methods as below: Single() SingleOrDefault() First() FirstOrDefault() Description Returns a single, specific element of a sequence Returns a single, specific […]

Read More

Difference between Lazy Loading and Eager Loading

Lazy/Deferred Loading In lazy loading, related objects (child objects) are not loaded automatically with its parent object until they are requested. By default LINQ supports lazy loading. With Lazy Loading, we only retrieve just the amount of data, which we need in a single query. When we need more data related to the initial data, […]

Read More

Automapper in ASP.NET Core

AutoMapper is an object-object mapper which allows you to solve the problem of manually mapping each property of a class with the same properties of another class. Read in details. How to use Automapper in ASP.NET Core 1) Add the main AutoMapper Package to your solution via NuGet. PM> Install-Package AutoMapper or   2)  Add […]

Read More

How to change the Action name in ASP.Net MVC

ActionName attribute can be used for changing the action name. Below is the sample code snippet to demonstrate more : [ActionName(“TestActionNew”)] public ActionResult Test() { return View(); } So in the above code snippet “Test” is the original action name and in “ActionName” attribute, name – “TestActionNew” is given. So the caller of this action […]

Read More

How to Overload the Action Method in ASP.NET MVC

In this article, we will learn how to overload an action method in asp.net MVC with example. In Asp.Net MVC, We can overload an Action method via action name attribute . Action methods must be public because private reflection isn’t permitted in medium trust. Action methods cannot be static because all the useful properties that hang […]

Read More

NonAction Method in Asp.Net MVC

In ASP.NET MVC, every public method of controller is accessible via URL regardless of return type, so if we have created any public method in controller which is not intended to serve as action method then also it is accessible via URL. One solution is that keep this method as private or protected but some time […]

Read More

Child Action Methods in ASP.Net MVC

In this article, We will learn how to use and where to use Child Action methods. A ChildAction method is an action method which can be accessible from the View only and restricts us to access via an URL. If we try to invoke this action via an URL then it prompts us an error message. We […]

Read More

Token Based Authentication using ASP.NET Web API 2, Owin, and Identity

As I stated before we’ll use token based approach to implement authentication between the front-end application and the back-end API, as we all know the common and old way to implement authentication is the cookie-based approach were the cookie is sent with each request from the client to the server, and on the server it is […]

Read More

Exception handling in ASP.NET MVC

In this article, we will learn how to use exception handling in Asp.Net MVC and which one is the best technique and why. In Asp.Net MVC, we can handle exception by multiple way as below Try Catch block:- It is the traditional way to handle exception. In this way, we simply use the try and […]

Read More

Routing in MVC

Routing is a pattern matching system that handles the incoming request and figure out what to do with that request. At runtime, Routing engine use the Route table for matching the incoming request’s URL pattern against the URL patterns defined in the Route table. In Convention based routing, We need to define routes in the […]

Read More

Asp.Net MVC 6 new feature

Cloud-optimized Framework:  Asp.NET MVC 6 (vNext) includes new cloud-optimized versions of MVC, Web API, Web Pages, SignalR, and Entity Framework. .NET vNext support true side-by-side deployment. If your app is using cloud-optimized subset of .NET vNext, you can deploy all of your dependencies including the .NET vNext (cloud optimized) by uploading bin to hosting environment. In […]

Read More

How to call controller from React in Asp.Net MVC

Here i will explain how to call controller from “React” in  Asp.Net MVC  with below example: Now Create a ActionMethod that will returns message in the Home Controller ass below code public JsonResult GetMessage() { return Json(new { result = “Hello World From ReactJS Controller” }, JsonRequestBehavior.AllowGet); } Now create jsx file and write code to get the data […]

Read More

How to Implement the Repository Pattern in ASP.NET MVC Application

The Repository Pattern is one of the most popular patterns to create an enterprise level application. It restricts us to work directly with the data in the application and creates new layers for database operations, business logic and the application’s UI. If an application does not follow the Repository Pattern, it may have the following […]

Read More

Logging and Tracing in Asp.Net MVC

Here, I am explaining the format of logs and tracing files in more readable form using Log4Net. Web config <!–Logging with Log4net –> <configSections> <section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” /> </configSections> <!–Logging with Log4net –> <!–LogFile Settings(Log4net): START –> <log4net> <!–Implementation Of FileAppender Starts Here!!–> <appender name=”LogFileAppender” type=”log4net.Appender.FileAppender”> <param name=”File” type=”log4net.Util.PatternString” value=”ErrorLogs\\ErrorLog_%date{yyyy-MM-dd}.log” /> <param name=”AppendToFile” value=”true” […]

Read More

Multiple Result Sets from database in Entity Framework

Stored Procedures with Multiple Result Sets Sometimes when using stored procedures you will need to return more than one result set. This scenario is commonly used to reduce the number of database round trips required to compose a single screen. Prior to EF5, Entity Framework would allow the stored procedure to be called but would only […]

Read More