NET Centric Computing - Old Questions

2. Explain the architecture and design principles of .NET. Create methods to insert, update, delete and read all data for the table Student having following fields StudentId(int), Name varchar(200), RollNo (int), Class varchar(50) using Entity Framework.

10 marks | Asked in Model Question

.NET is tiered, modular, and hierarchal. Each tier of the .NET Framework is a layer of abstraction. .NET languages are the top tier and the most abstracted level. The common language runtime is the bottom tier, the least abstracted, and closest to the native environment. This is important since the common language runtime works closely with the operating environment to manage .NET applications. The .NET Framework is partitioned into modules, each with its own distinct responsibility. Finally, since higher tiers request services only from the lower tiers, .NET is hierarchal. The architectural layout of the .NET Framework is given below.

            Figure: An overview of the .NET architecture.

  • Common Language Runtime (CLR) is the heart of the .Net Framework. It resides above the operating system and handles all .Net applications. It handles garbage collection, Code Access Security (CAS) etc.
  • Common Language Infrastructure (CLI) provides a language-independent platform for app development and its performance. It also includes the function for exception handling, waste collection, security, etc.
  • Common Type System(CTS) specifies a standard that represent what type of data and value can be defined and managed in computer memory at runtime. For example, in C# we define data type as int, while in VB.NET we define integer as a data type.
  • Common language Specification(CLS)  is a subset of common type system (CTS) that defines a set of rules and regulations which should be followed by every language that comes under the .net framework. For example, in C# and VB.NET language, the C# language terminate each statement with semicolon, whereas in VB.NET it is not end with semicolon, and when these statements execute in .NET Framework, it provides a common platform to interact and share information with each other.
  • FCL (Framework Class Library) provides the various system functionality in the .NET Framework, that includes classes, interfaces and data types, etc. to create multiple functions and different types of application such as desktop, web, mobile application, etc.

Design principles of .NET:

  • Interoperability
  • Portability
  • In-built security mechanism
  • Robust memory management
  • Simplified deployment
  • Asynchronous Programming
  • High Performance

Second Part

namespace CSharpExamples

{

    class EFCoreTest

    {

        private StudentContext _context = new StudentContext();

        public List<Student> GetAll()

        {

            return _context.tblStudent.ToList();

        }

        public void InsertStudent(Student emp)

        {

            _context.Add(emp);

            _context.SaveChanges();

        }

        public int EditStudent(Student emp)

        {

            if (emp.StudentId == -1)

            {

                return 0;

            }

            var stud = _context.tblStudent.Find(emp.StudentId);

            if (stud == null)

            {

                return 0;

            }

            int updatedCount = 0;

            try

            {

               _context.Update(stud);

               updatedCount = _context.SaveChanges();

            }

            catch (DbUpdateConcurrencyException)

            {

                return 0;

            }

            return updatedCount;

        }

        public int deleteStudent(int StudentId)

        {

            if (StudentId == -1)

            {

                return 0;

            }

            var stud = _context.tblStudent

                .FirstOrDefault(m => m.StudentId == StudentId);

            if (stud == null)

            {

                return 0;

            }

            _context.tblStudent.Remove(stud);

            int updatedCount =  _context.SaveChanges();

            return updatedCount;

        }

        public void showStudents(List<Student> students)

        {

            foreach (Student student in students)

            {

                Console.WriteLine("Student ID = " + student.StudentId);

                Console.WriteLine("Student Name = " + student.Name);

                Console.WriteLine("Student RollNo = " + student.RollNo);

                Console.WriteLine("Student Class = " + student.Class);

            }

        }

}

Class Program

    {

        static void Main(string[] args)

        {      

            EFCoreTest test = new EFCoreTest();

//Read All Students

            List<Employee> employees = test.GetAll();

            Console.WriteLine("Initial Records");

            test.showStudents(employees);

            //Insert Student

            Employee stud = new Employee();

            stud.Name = "Ram";

            stud.RollNo = 31;

stud.Class = "Sixth Sem";

            test.InsertStudent(stud);

            Console.WriteLine("After Insert");

            test.showStudents(employees);

            //Update Student

            stud.Name = "UpdatedName";

            test.EditStudent(stud);

            Console.WriteLine("After Update");

            test.showStudents(employees);

            //Delete Student

            test.deleteStudent(stud.EmployeeId);

            Console.WriteLine("After Delete");

            test.showStudents(employees);

            Console.ReadLine();

        }

    } 

}