/// <summary> /// Override for configuring entity mapping. /// </summary> /// <param name="modelBuilder"></param> protected internal override void OnModelBuilding(EntityModelBuilder modelBuilder) { modelBuilder.Entity <Address>(entity => { //entity.ToTable( "Addresses" ); //entity.Column( p => p.AddressId ) // .IsKey(); }); base.OnModelBuilding(modelBuilder); }
/// <summary> /// Override for configuring entity mapping. /// </summary> /// <param name="modelBuilder"></param> protected internal override void OnModelBuilding(EntityModelBuilder modelBuilder) { //config.Entity<Customer>( entity => //{ // entity.Column( p => p.Orders ); // entity.Column( p => p.Id ) // .IsKey(); // entity.HasMany( p => p.Orders ) // .WithForeignKey<Order>( o => o.CustomerId ); //} ); //config.Entity<Order>( entity => //{ // entity.Column( p => p.Id ) // .IsKey(); // entity.HasOne( p => p.Customer ) // .WithForeignKey( p => p.CustomerId ) // .Name( "CustomerFK" ); // //.IsRequired(); // entity.HasMany( p => p.Products ) // .WithForeignKey<Product>( p => p.OrderId ); //} ); modelBuilder.Entity <Supplier>(entity => { entity.ToTable("Suppliers"); entity.Column(p => p.Id) .IsKey(); entity.Column(p => p.Name) .IsRequired(); }); modelBuilder.Entity <Product>(entity => { entity.ToTable("Products"); entity.Column(p => p.Id) .IsKey(); entity.Column(p => p.Price) .IsRequired(); entity.HasIndex(p => p.Name) .Name("IX_Products_Name") .IsUnique(); entity.HasOne(p => p.Supplier) // The relationship property .WithForeignKey(p => p.SupplierId) // The foreign key. The Foreign Key constrain is on the Products table (Non-generice WithForeignKey). .References <Supplier>(p => p.Id); // The reference table and key entity.HasMany(p => p.Parts) .WithForeignKey <Part>(parts => parts.ProductKey) .References <Product>(p => p.Id); }); base.OnModelBuilding(modelBuilder); }