Friday, 16 November 2012

Code First mappings using Fluent API


yes, previously we uses EF-Code first classes then we mapping between the POCO classes in code-first model

but using Fluent -API automatics this connvation. which will minizes coding


public class Conn : DbContext
    {
        public DbSet<Employee> emps { get; set; }
        public DbSet<Departments>  dept{ get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
               //  modelBuilder.Entity<Employee>()               //.HasRequired(a => a.Dept)
               //.WithMany()                   
               //.HasForeignKey(u => u.Eaddress);

            //modelBuilder.Entity<Employee>().
                              
           // base.OnModelCreating(modelBuilder);

            //      or

             
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }
    }



No comments:

Post a Comment