This comprehensive demo shows the evolution from raw ADO.NET to Entity Framework Core, demonstrating Code-First approach with migrations and CRUD operations.
Aspect | ADO.NET (Previous Demo) | Entity Framework Core |
---|---|---|
Database Operations | Manual SQL queries | LINQ expressions |
Connection Management | Manual open/close | Automatic |
Object Mapping | Manual mapping | Automatic ORM |
Schema Management | Manual table creation | Code-First migrations |
Type Safety | String-based queries | Strongly-typed |
1. Microsoft.EntityFrameworkCore 8.0.0 - Core EF functionality
2. Microsoft.EntityFrameworkCore.Design 8.0.0 - Design-time tools
3. Microsoft.EntityFrameworkCore.SqlServer 8.0.0 - SQL Server provider
4. Microsoft.EntityFrameworkCore.Tools 8.0.0 - Migration tools
Install-Package Microsoft.EntityFrameworkCore -Version 8.0.0
Install-Package Microsoft.EntityFrameworkCore.Design -Version 8.0.0
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 8.0.0
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 8.0.0
[Table("Employee")] // Maps to 'Employee' table instead of 'Emp'
public class Emp
{
[Column("No")] // Maps to 'No' column
[Key] // Primary key designation
public int No { get; set; }
[Column("Name")]
[StringLength(50)] // Varchar(50) constraint
public string Name { get; set; }
[Column("Address")]
[StringLength(50)] // Varchar(50) constraint
public string Address { get; set; }
}
Key Features:
[Table]
specifies actual table name[Column]
maps properties to specific columns[StringLength]
creates varchar limitations[Key]
designates the primary key