Abhishek Kumar
How to maping in Code First approach
By Abhishek Kumar in .NET on Sep 27 2017
  • Rushyanth Reddy
    Aug, 2018 22

    Using AutoMappers to map between the Domain models to the Entity models

    • 0
  • Tushar Bharambe
    Jan, 2018 10

    Code-First will create the database tables with the name of DbSet properties in the context class - Employees and Departments in this case. You can override this convention and can give a different table name than the DbSet properties, as shown below.namespace CodeFirst_Tutorials {public class EmployeeContext: DbContext {public EmployeeDBContext(): base() {}public DbSet Employees { get; set; }public DbSet Departments { get; set; }protected override void OnModelCreating(DbModelBuilder modelBuilder){//Configure default schemamodelBuilder.HasDefaultSchema("Admin");//Map entity to tablemodelBuilder.Entity().ToTable("EmployeeInfo");modelBuilder.Entity().ToTable("DepartmentInfo","dbo");}} }As you can see in the above example, we start with the Entity() method. Most of the time, you have to start with the Entity() method to configure it using Fluent API. We have used ToTable() method to map Employee entity to EmployeeInfo and Department entity to DepartmentInfo table. Notice that EmployeeInfo is in Admin schema and DepartmentInfo table is in dbo schema because we have specified dbo schema for DepartmentInfo table.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS