Entity Framework Tutorial
Lesson 50 of 69 · Part 15 Conditional Mapping in entity framework with code first · Database
Part 15 Conditional Mapping in entity framework with code first
Text version of the video
http://csharp-video-tutorials.blogspot.com/2014/05/part-15-conditional-mapping-in-entity.html
Slides
http://csharp-video-tutorials.blogspot.com/2014/05/part-15-conditional-mapping-in-entity_31.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
In Part 14, we discussed Conditional Mapping in entity framework with database first approach. Please watch Part 14 before proceeding. In this video we will discuss Conditional Mapping in entity framework with code first approach.
To implement Conditional Mapping with code first override OnModelCreating() method
using System.Data.Entity;
namespace Demo
{
public class EmployeeDBContext : DbContext
{
public DbSet[Employee] Employees { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity[Employee]()
.Map(m =] m.Requires(“IsTerminated”)
.HasValue(false))
.Ignore(m =] m.IsTerminated);
base.OnModelCreating(modelBuilder);
}
}
}