EF and MVC - Database is not getting created RRS feed

  • Question

  • I created MVC application and it's using EF. I am using code-first approach.

    I have created Entity class as follow.

     public class AlwaysInTouchEntities: DbContext
            public DbSet<Device> Devices { get; set; }
            public DbSet<Request> Requests { get; set; }
            public DbSet<RequestDetail> RequestDetails { get; set; }

    I have following code in web.config.

        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
            <parameter value="Data Source=.\SQLEXPRESS; Integrated Security=true; MultipleActiveResultSets=True" />

    I have following code in Global.asax.cs

     protected void Application_Start()
                System.Data.Entity.Database.SetInitializer(new Mvc3Intranet.ResourceManager.Models.SampleData());

    Also I created instance in HomeController.cs

     public class HomeController : Controller
            AlwaysInTouchEntities _context = new AlwaysInTouchEntities();
            public ActionResult Index()
                ViewBag.Message = "Welcome to ASP.NET MVC!";
                return View();
            public ActionResult About()
                return View();

    But DB is not getting created :(

    What might I have missed? Please help me

    Many Thanks Deepak

    Monday, July 30, 2012 5:48 AM


  • Resolved :)

    We have to make use of entities for first time. 

    Example : 

    _context .Devices.ToList();

    Many Thanks Deepak

    • Marked as answer by Deepak RA0 Monday, July 30, 2012 12:51 PM
    Monday, July 30, 2012 12:51 PM