Reputation: 1046
I'm following the tutorial as shown in the link below:
Creating an Entity Framework data model for ASP.NET MVC application
But while running the application, the following exception comes:
System.IO.FileNotFoundException: Could not load file or assembly 'Vag_Infotech' or one of its dependencies. The system cannot find the file specified.
My web.config file is as follows:
<connectionStrings>
<add name="CollegeDbContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=VInfotech;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
</connectionStrings>
<contexts>
<context type="Vag_Infotech.DAL.CollegeDbContext, Vag_Infotech">
<databaseInitializer type="Vag_Infotech.DAL.CollegeDatabaseInitializer, Vag_Infotech"></databaseInitializer>
</context>
</contexts>
CollegeDbContext Class:
namespace Vag_Infotech.DAL
{
public class CollegeDbContext : DbContext
{
public CollegeDbContext()
: base("CollegeDbContext")
{
}
public DbSet<Student> Students { get; set; }
public DbSet<Course> Courses { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
}
The exception comes in the StudentController.cs class:
Upvotes: 2
Views: 3613
Reputation: 105
Run Developer CommandPropmpt for VisualStudio 2012 as Administrator and then run the command over it.
Upvotes: 0
Reputation: 1046
Great News,
I solved my problem. I initialized my DatabaseInitializer from the Global.asax
file. Take a look on the code below:
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 CollegeDatabaseInitializer());
}
}
I simply initialize my CollegeDatabaseInitializer()
in the Application_Start()
. But please note that remove the <contexts>
from the Web.Config
file. Thanks.
Upvotes: 6