Part 11 Entity splitting in entity framework with code first approach04:33

  • 0
Published on December 31, 2017

Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

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);
}
}

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

https://iavec.com.br/

Enjoyed this video?
"No Thanks. Please Close This Box!"