<pre lang="xml"><connectionStrings> <add name="SchoolDBContext" connectionString="data source=home;initial catalog=School;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /></connectionStrings> </pre> <pre lang="c#"> <pre lang="xml">namespace unviresty.Dal { using System; using System.Data.Entity; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using unviresty.Models; public partial class SchoolContext : DbContext { public SchoolContext() : base("name=SchoolDBContext") { Database.SetInitializer<SchoolContext>(new CreateDatabaseIfNotExists<SchoolContext>()); } public DbSet<student> Students { get; set; } public DbSet<Enrollment> Enrollments { get; set; } public DbSet<Course> Courses { get; set; } //protected override void OnModelCreating(DbModelBuilder modelBuilder) //{ // modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); //} protected override void OnModelCreating(DbModelBuilder modelBuilder) { } } } </pre> <pre lang="c#"> protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); } </pre>
<pre lang="c#"> protected void Application_Start() { System.Data.Entity.Database.SetInitializer(new DropCreateDatabaseIfModelChanges<schoolcontext>()); using (var context = new SchoolContext()) { context.Database.Initialize(force: true); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)