Monday 15 April 2013

c# - ASP.NET MVC 3 - DBContext Class Not Being Executed -


I am trying to sow my application with some test data via AF code, when the app starts is.

What I'm looking for:

When I run the app, the execution happens:

  Application_Start () {}   

And then there is land at Application_Start () at one time:

  Database .setilizer & lt; Locator contaxes & gt; (New drop crete database always & lt; locator contax & gt; ());   

But this does not ever make it in DBCTTENTC class (ClubLocator Contracts), which is where seeds are also among other things.

How can I fix it, it will be appreciated.

My global.assx cs file

  // global Application_Start () {Database.SetInitializer & lt; LocatorContext & gt; (New DropCreateDatabaseAlways & lt; LocatorContext & gt; ()); AreaRegistration.RegisterAllAreas (); RegisterGlobalFilters (GlobalFilters.Filters); RegisterRoutes (RouteTable.Routes); }   

My DBContext class

  // using the ClubLocatorContext.cs system; Using System.Collections.Generic; Using System.Data.Entity.ModelConfiguration.Conventions; Using System.Linq; Using System.Web; Using System.Data.Entity; Using System.Data.Entity.Infrastructure; Using ClubLocator.Models; Using ClubLocator. Models. ViewModels; Namespace Club Locator DAL {Public Class Locator Contact: DBCOntax {Public DBSet and LT; Prospect & gt; Possibilities {get; Set; } Safe Override Zero OnModelCreating (DbModelbuilder Modalbuilder) {base.OnModelCreating (ModelBuilder); ModelBuilder.Conventions.Remove & LT; PluralizingTableNameConvention & gt; (); } Public zero seed (locator content reference) {var probability = new list & lt; Chance & gt; {New prospect {first name = "john", last name = "smith", address 1 = "1313 mockingbird lane", email = "jsmith@example.com"}}; Chance.Reerich (R => References. Prospects.ed (R)); Context.SaveChanges (); } Public class DropCreateIfChangeInitializer: DropCreateDatabaseIfModelChanges & lt; LocatorContext & gt; {Safe Override Seed (Locator Context Reference) {reference.Seed (reference); Base.Seed (reference); }} Public class CreateInitializer: DropCreateDatabaseAlways & lt; LocatorContext & gt; {Safe Override Seed (Locator Context Reference) {reference.Seed (reference); Base.Seed (reference); }} Static Locator Contexte () {# DEBUG Database.SetInitializer & lt; LocatorContext & gt; (New DropCreateIfChangeInitializer ()); #else Database.SetInitializer & lt; LocatorContext & gt; (New CreateInitializer ()); #endif}}    

  new DropCreateIfChangeInitializer (). Early database (new LocatorContact) ());    

No comments:

Post a Comment