using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using IdeaBlade.EntityModel;

namespace CodeFirstWalk.Model2 {
  [DataSourceKeyName("CodeFirstWalk2")]
  class ProductDbContext2 : DbContext {
    public ProductDbContext2(string connection)
      : base(connection) {
      ConfigureCodeFirstForSqlServer();
      // Do not use in production; for early development only
      Database.SetInitializer(
          new DropCreateDatabaseIfModelChanges<ProductDbContext2>());
    }

    static void ConfigureCodeFirstForSqlServer() {
      // Set base connection string
      const string baseConnectionString =
      "Data Source=.; " +
      "Integrated Security=True; " +
      "MultipleActiveResultSets=True; " +
      "Application Name=CodeFirstWalk"; // change to suit your app
      Database.DefaultConnectionFactory = new SqlConnectionFactory(baseConnectionString);
    }


    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
      modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
      modelBuilder.Ignore<EntityAspect>();
    }

    public DbSet<Supplier2> Suppliers2 { get; set; } // root entity for model discovery
    //public DbSet<Category> Categories { get; set; } // Not necessary because discovered
    //public DbSet<Product> Products { get; set; } // Not necessary because discovered
  }
}
