Part 11 Entity splitting in entity framework with code first approach

preview_player
Показать описание
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);
}
}
Рекомендации по теме
Комментарии
Автор

Venkat sir .please tell the When to use IEnumerable<T>, ICollection<T>, IList<T> and iQueryable<T> what is difference..When use one over another and where we exactly Thanks 

mageshwarank
Автор

Hi Venkat,
First of all thank you very much for your effort, your tutorials were very use full, every topic was very precise and every one can grab the technology easily by watching your videos. 
I have one doubt is it mandatory to put all the controls in form tag(beginform) with in view(razor) in mvc. or it is needed when view is making post back.in normal asp.net every thing should be in form tag.here we need it or not in mvc.
please provide me the answer as soon as possible

chandrashekarb
Автор

I'm sorry. is this useful just for one to one relationships?

johnkoutman
visit shbcf.ru