I am reading this book, and it tries to use initializer to Create the DB each time the application runs, so the code snippet is like this:
protected void Application_Start() {
Database.SetInitializer(new DropCreateDatabaseAlways<MusicStoreDB>());
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
I can't understand this part:
new DropCreateDatabaseAlways<MusicStoreDB>()
What is this syntax? what does <MusicStoreDB>()
mean?
I know it's not a fancy question, but I need help here.
Thanks.
That syntax is called generics. In a nutshell (a very tiny nutshell), imagine that your app had more than 1 database (e.g. MusicStoreDB, MovieStoreDB, etc), you could use the same DropCreateDatabaseAlways class with the different db types. In other words, generics let you define classes and functions that can act on many different types, for example
List<int>, List<string>, List<MyAwesomeClass>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With