A simple ASP.NET Core web application demonstrating Entity Framework Core integration with SQL Server database for managing student records.
- Display student records with ID, Name, and CGPA
- Entity Framework Core integration
- SQL Server database connectivity
- MVC architecture pattern
- Responsive web interface
- Framework: ASP.NET Core MVC
- ORM: Entity Framework Core
- Database: SQL Server
- Language: C#
- Frontend: HTML, CSS, JavaScript (via MVC Views)
EntityFrameworkCorePractice/
├── Controllers/
│ └── HomeController.cs # Main controller handling student data
├── Models/
│ ├── StudentModel.cs # Student entity model
│ ├── StudentDbContext.cs # Database context
│ └── ErrorViewModel.cs # Error handling model
├── Views/
│ └── Home/
│ ├── Index.cshtml # Student list view
│ └── Privacy.cshtml # Privacy page
└── Program.cs # Application configuration
The application uses a single Student table with the following structure:
| Column Name | Data Type | Description |
|---|---|---|
| s_id | INT (Primary Key) | Student ID |
| full_name | VARCHAR(100) | Student's full name |
| c_gpa | DECIMAL(3,2) | Student's CGPA (0.00-4.00) |
- .NET 6.0 or later
- SQL Server (LocalDB, Express, or Full version)
- Visual Studio 2022 or Visual Studio Code
-
Clone the repository
git clone <repository-url> cd EntityFrameworkCorePractice
-
Configure Database Connection
Update the connection string in
appsettings.json:{ "ConnectionStrings": { "dbcs": "Server=(localdb)\\MSSQLLocalDB;Database=StudentDB;Trusted_Connection=true;MultipleActiveResultSets=true;TrustServerCertificate=True;" } } -
Install Dependencies
dotnet restore
-
Create Database and Tables
Run the following commands in Package Manager Console:
Add-Migration InitialCreate Update-Database
-
Run the Application
dotnet run
The application will be available at
https://localhost:5001orhttp://localhost:5000
- View Students: Navigate to the home page to see all registered students
- Database Operations: Currently supports read operations (display student list)
- Uses Data Annotations for database mapping
- Custom column names and data types
- Primary key configuration
- Simple DbContext implementation
- Configured with dependency injection
- SQL Server provider integration
- Dependency injection of DbContext
- Retrieves and displays student data
- Standard MVC error handling
The application is configured in Program.cs with:
- MVC services registration
- Entity Framework DbContext configuration
- SQL Server connection setup
- Standard ASP.NET Core middleware pipeline
# Add new migration
Add-Migration <MigrationName>
# Update database
Update-Database
# Remove last migration
Remove-Migration
# View migration history
Get-Migrations-
Connection String Errors
- Verify SQL Server is running
- Check connection string format
- Ensure database exists
-
Migration Issues
- Delete
Migrationsfolder and recreate - Check model configurations
- Verify DbContext registration
- Delete
-
Dependency Injection Errors
- Ensure DbContext is registered in
Program.cs - Check constructor parameters match registered services
- Ensure DbContext is registered in
Note: This is a basic implementation intended for learning Entity Framework Core concepts. For production use, consider implementing proper error handling, logging, security measures, and testing.
