【发布时间】:2013-12-18 09:18:11
【问题描述】:
我正在按照以下链接所示的教程进行操作:
Creating an Entity Framework data model for ASP.NET MVC application
但在运行应用程序时,出现以下异常:
System.IO.FileNotFoundException:无法加载文件或程序集“Vag_Infotech”或其依赖项之一。系统找不到指定的文件。
我的web.config文件如下:
<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 类:
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>();
}
}
}
StudentController.cs 类中出现异常:
【问题讨论】:
-
我还没有制作它,因为在教程中它被指定为制作一个 dll。 @Tobberoth
-
您的命名空间是否命名为 Vag_Infotech?似乎很难找到它。你能发布你的 CollegeDbContext 类的代码吗?或者可能是 DAL 文件夹中的初始化程序代码,因为这似乎是关键问题。
-
@Tobberoth 是的。我在创建应用程序时犯了一个错误,我输入了应用程序 Vag Infotech 的名称。
-
嗯,CollegeDbContext 对我来说看起来不错。。您可以使用“在文件中查找”来搜索 Contoso,看看是否有遗漏的地方将 ContosoUniversity 更改为 Val_Infotech?
-
看着它@Tobberoth
标签: c# asp.net visual-studio-2013 asp.net-mvc-5