1.

Explain the concept of MVC scaffolding

Answer»

When we want to use a code for pre-installed web API and MVC, we use scaffolding  .it is a quite quick process which interacts with the data model. The main use of adding scaffolding is to interact with code and data model fast. It reduces the amount of time to develop standard data operations in your project.

Scaffold templates are used to generate code for basic CRUD operations and writes a method specific to each DML OPERATION against your database with the help Entity FRAMEWORK. For this, they use VISUAL Studio T4 templating system to generate views.

Let's understand it with an example.

Let's create a simple class by the name of Employee.cs.

Add some properties to Employee class USING the following code

using System; namespace MVCScaffoldingDemo.Models {   public class Employee{      public int ID { get; SET; }      public string Name { get; set; }      public DateTime JoiningDate { get; set; }      public int Age { get; set; }   } }

We need to add another class, which will communicate with Entity Framework to retrieve and save the data.

using System; using System.Data.Entity; namespace MVCScaffoldingDemo.Models{   public class Employee{      public int ID { get; set; }      public string Name { get; set; }      public DateTime JoiningDate { get; set; }      public int Age { get; set; }   }   public class EmpDBContext : DbContext{      public DbSet<Employee> Employees { get; set; }   } }

As we know that EmpDBContext which is derived from the DB.Context class, In this class, we have one property with the name DbSet, which basically represents the entity which you want to query and save.



Discussion

No Comment Found