filmov
tv
Part 11 Entity splitting in entity framework with code first approach

Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
Entity Framework - All Text Articles
Entity Framework - All Slides
Entity Framework Playlist
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
Entity splitting refers to mapping an entity to two or more tables when the tables share a common key. We discussed, Entity splitting with database first approach in Part 10
By default, Entity Framework code-first creates one Employees table based on Employee class
To map the Employee entity to 2 tables -- Employees & EmployeeContactDetails, override OnModelCreating() method of the DBContext class
public class EmployeeDBContext : DbContext
{
public DbSet[Employee] Employees { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity[Employee]()
// Specify properties to map to Employees table
.Map(map =]
{
map.Properties(p =] new
{
p.EmployeeId,
p.FirstName,
p.LastName,
p.Gender
});
map.ToTable("Employees");
})
// Specify properties to map to EmployeeContactDetails table
.Map(map =]
{
map.Properties(p =] new
{
p.EmployeeId,
p.Email,
p.Mobile,
p.Landline
});
map.ToTable("EmployeeContactDetails");
});
base.OnModelCreating(modelBuilder);
}
}
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
Entity Framework - All Text Articles
Entity Framework - All Slides
Entity Framework Playlist
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
Entity splitting refers to mapping an entity to two or more tables when the tables share a common key. We discussed, Entity splitting with database first approach in Part 10
By default, Entity Framework code-first creates one Employees table based on Employee class
To map the Employee entity to 2 tables -- Employees & EmployeeContactDetails, override OnModelCreating() method of the DBContext class
public class EmployeeDBContext : DbContext
{
public DbSet[Employee] Employees { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity[Employee]()
// Specify properties to map to Employees table
.Map(map =]
{
map.Properties(p =] new
{
p.EmployeeId,
p.FirstName,
p.LastName,
p.Gender
});
map.ToTable("Employees");
})
// Specify properties to map to EmployeeContactDetails table
.Map(map =]
{
map.Properties(p =] new
{
p.EmployeeId,
p.Email,
p.Mobile,
p.Landline
});
map.ToTable("EmployeeContactDetails");
});
base.OnModelCreating(modelBuilder);
}
}
Комментарии