I need to populate an element from the Database, first thing when I compile/run my MVC3 application.
I have a static class and static method to populate the element. I just need to know how I could somehow call the method at the startup of my application.
Here’s the code:
public static class Select_Brands
{
public static IQueryable<Brand> BrandsQ { get; set; }
public static IQueryable<Brand> GetBrands()
{
using (Online_Store_DBEntities EFModel = new Online_Store_DBEntities())
{
BrandsQ = EFModel.Brands;
}
return BrandsQ;
}
}
Is there any way ?
In every MVC Application you have a Global.asax like in an ASP.NET Application and you can run code in Application_Start() Method.
But you should think about where to persist the data and what you really use this for.