c# - Executing IDatabaseInitializer -


i've implemented own database initializer inherited dropdatabaseifmodelchanges<>()

so:

public class mydatabaseinitializer : dropdatabaseifmodelchanges<mydatabasecontext>()

i use in global.asax file , do:

protect void application_start() {     // normal app start stuff      database.setinitializer(new mydatabaseinitializer());      // create ninject kernel , set dependencyresolver here } 

now sets initializer want execute void initializedatabase(tcontext context); drops , creates database.

it when gets line executing database request such as:

_repository.mytable.tolist()

note, i'm using repository pattern , ninject.

however wish execute drop create on application start!

how that?

okay, nailed it.

my idatabaseinitializer implementation looks this:

public class mydatabaseinitializer : dropdatabaseifmodelchanges<mydatabasecontext>() {     public mydatabaseinitializer() : base ()     {         var context = new mydatabasecontext();          seed(context);          base.initializedatabase(context);          // other things need here database     }      public override seed(uxcontext context)     {         // seed data here     } }  

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -