TU BCA DotNet Technology Master Guide: C# OOP, ASP.NET Core MVC Architecture & Entity Framework CRUD
Author: Bhuban Subedi | Subject: DotNet Technology (CACS301) | Semester: Fifth Semester
In modern enterprise software engineering, Microsoft’s .NET ecosystem (.NET 8/9, C#, ASP.NET Core) powers high-throughput enterprise web portals, banking backends, and cloud microservices. In the Tribhuvan University BCA fifth semester, DotNet Technology (CACS301) trains students in modern C# object-oriented programming, Language Integrated Query (LINQ), ASP.NET Core Model-View-Controller (MVC) web architecture, and Entity Framework Core (EF Core).
In the final 60-mark TU board examination and the 40-mark external laboratory viva, examiners routinely test C# Delegates and Events, Dependency Injection in ASP.NET Core, MVC Routing Lifecycles, and Entity Framework CRUD operations.
In this guide, I will walk you through these core frameworks with production-ready C# code.
1. .NET Core Architecture vs. Legacy .NET Framework
+-------------------+-----------------------------------+-----------------------------------+
| Parameter | Legacy .NET Framework (<= 4.8) | Modern .NET (.NET 6 / 7 / 8 / 9) |
+-------------------+-----------------------------------+-----------------------------------+
| **Platform** | Windows only. | Cross-platform (Windows, Linux, |
| | | macOS, Docker containers). |
+-------------------+-----------------------------------+-----------------------------------+
| **Performance** | Heavyweight monolithic runtime. | High-performance modular runtime, |
| | | Kestrel high-speed web server. |
+-------------------+-----------------------------------+-----------------------------------+
| **Open Source** | Proprietary Microsoft stack. | 100% Open Source under MIT/Apache.|
+-------------------+-----------------------------------+-----------------------------------+
2. Advanced C#: Delegates, Events & LINQ
A Delegate is a type-safe function pointer in C# holding references to methods with matching return types and parameter signatures.
using System;
using System.Collections.Generic;
using System.Linq;
// 1. Declaring a Custom Delegate
public delegate void NotificationHandler(string message);
public class Program
{
public static void Main()
{
// 2. Delegate Instantiation & Multicast Invocation
NotificationHandler notifier = SendEmailAlert;
notifier += SendSmsAlert; // Multicasting
notifier("Critical Database Backup Completed!");
// 3. LINQ (Language Integrated Query) Demonstration
var studentScores = new List<int> { 45, 88, 92, 60, 35, 76, 95 };
// LINQ Query Expression: Filter Distinction scores (>= 80) and Sort
var distinctionList = from score in studentScores
where score >= 80
orderby score descending
select score;
Console.WriteLine("\n--- Distinction Scores (LINQ) ---");
foreach (var sc in distinctionList)
{
Console.WriteLine($"Score: {sc}");
}
}
public static void SendEmailAlert(string msg) => Console.WriteLine($"[EMAIL SENT]: {msg}");
public static void SendSmsAlert(string msg) => Console.WriteLine($"[SMS SENT]: {msg}");
}
3. ASP.NET Core MVC Architectural Pattern
ASP.NET Core separates concerns into 3 core layers:
[Browser / Client Request]
│
▼
[Controller] ◄─── (Fetches / Updates Data) ───► [Model (Database / EF Core)]
│
(Passes ViewModel)
│
▼
[View (Razor .cshtml)] ───► [Rendered HTML Response to Browser]
4. Entity Framework Core (EF Core) CRUD Implementation
In TU lab examinations, building a full MVC Controller with EF Core database context is a recurring 10-to-15 mark practical question.
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;
// 1. Model Entity
public class Student
{
public int Id { get; set; }
public string FullName { get; set; } = string.Empty;
public string RollNumber { get; set; } = string.Empty;
public double Gpa { get; set; }
}
// 2. EF Core Database Context
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public DbSet<Student> Students => Set<Student>();
}
// 3. ASP.NET Core MVC Controller with Dependency Injection
public class StudentsController : Controller
{
private readonly ApplicationDbContext _context;
// Injecting DB Context via Constructor DI
public StudentsController(ApplicationDbContext context)
{
_context = context;
}
// GET: /Students/Index
public async Task<IActionResult> Index()
{
List<Student> students = await _context.Students.AsNoTracking().ToListAsync();
return View(students);
}
// POST: /Students/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("FullName,RollNumber,Gpa")] Student student)
{
if (ModelState.IsValid)
{
_context.Add(student);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(student);
}
}
Frequently Asked Questions (FAQ)
Q1: What is Dependency Injection (DI) in ASP.NET Core?
Dependency Injection is a built-in architectural design pattern that allows classes to receive dependencies from external sources (such as database contexts, loggers, or email services) rather than creating them directly via new, promoting loose coupling and unit testability.
Q2: What are the three service lifetimes in ASP.NET Core DI?
- Transient: Created each time they are requested.
- Scoped: Created once per client HTTP request.
- Singleton: Created the first time they are requested and stay active throughout the application lifetime.



