0
votes

I am getting the following error in my global.aspx file

Error 1 The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {

        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        Database.SetInitializer(new DropCreateDatabaseIfModelChanges<SalesERPDAL>());
    }

}

Error 1 The type arguments for method 'System.Data.Entity.Database.SetInitializer(System.Data.Entity.IDatabaseInitializer)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Error 2 The type or namespace name 'SalesERPDAL' could not be found (are you missing a using directive or an assembly reference?)

I don't get the errors, it was working until I got an error about The model backing the context has changed since the database was created.

What do I need to do to get it working ?

2
Is SalesERPDAL is the same namespace? If not do you need to add a using directive? - D Stanley
got it thanks !!! didn't have the namespace - Aindriú
Glad it's working - since this is basically a typo I'm going to vote to close it as such. - D Stanley

2 Answers

3
votes

Add generic argument with your context type to SetInitializer method:

Database.SetInitializer<SalesERPDAL>(new DropCreateDatabaseIfModelChanges<SalesERPDAL>());
1
votes

Step 1 - Write using statement at the top of the Global.asax file >> using System.Data.Entity; and using WebApplication1.DataAccessLayer; I solved this problem by adding above two using statements. It will drop the existing database and recreate the new database. But we will lose all data from old database. I face this problem :-(