Entity Framework Not Creating Database

前端 未结 3 549
长发绾君心
长发绾君心 2021-01-31 03:19

Been playing around with the Code First feature of Entity Framework 4.1 using an ASP.NET MVC 3 project.

However the database (SQL Server 2008 R2) does not automatically

3条回答
  •  难免孤独
    2021-01-31 03:53

    I know this was already answered by mazatsushi in the rightest way. But just to clarify it to begginers: Based in mazatsushi's answer what you have to do is to write:

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges());
            using (var context = new SorteoContext())
            {
                context.Database.Initialize(force: true);
            }
    

    inside Application_Start() function in Global.asax.cs and Boom! works!

提交回复
热议问题