Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
iam use this code but dont create database with tables
i dont where is problem

HTML
<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(&quot;name=SchoolDBContext&quot;)
        {
            Database.SetInitializer&lt;SchoolContext&gt;(new CreateDatabaseIfNotExists&lt;SchoolContext&gt;());
        }
        public DbSet&lt;student&gt; Students { get; set; }
        public DbSet&lt;Enrollment&gt; Enrollments { get; set; }
        public DbSet&lt;Course&gt; Courses { get; set; }
        //protected override void OnModelCreating(DbModelBuilder modelBuilder)
        //{
        //    modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
        //}
        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>
Posted

1 solution

C#
<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);
            }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900