Let's try to understand how we can use the Entity Framework Code First approach by working on a small application. Let's try to create a POCO for an employee, and see how we can use Entity Framework to perform CRUD operations on this model:
Let's start by creating the
Employee
model (1003OS_06_1_code.txt
):public class Employee { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string PhoneNumber { get; set; } public string EMailId { get; set; } }
If we use this model, the generated table name will be
Employees
, the column names will be the name of the properties, and theID
field will be treated as the primary key. All this will be because of the Code First conventions.If we want to override these default convention-based values and provide our values, then we can do this by updating the class and properties with the needed attributes:
[Table("Employees")] public class Employee...