Entity Framework Tutorial
Lesson 39 of 69 · Part 11 Entity splitting in entity framework with code first approach · Database
Part 11 Entity splitting in entity framework with code first approach
Text version of the video
http://csharp-video-tutorials.blogspot.com/2014/05/part-11-entity-splitting-in-entity.html
Slides
http://csharp-video-tutorials.blogspot.com/2014/05/part-11-entity-splitting-in-entity_21.html
Entity Framework – All Text Articles
http://csharp-video-tutorials.blogspot.com/2014/05/entity-framework-tutorial.html
Entity Framework – All Slides
http://csharp-video-tutorials.blogspot.com/2014/05/entity-framework-tutorial-slides.html
Entity Framework Playlist
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
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);
}
}