我正在构建一个非常简单的页面。这在运行VS时非常有效,但是当它被发布到服务器时,它会给出“找不到类型或命名空间名称'EmployeeDBContext'(你是否缺少using指令或程序集引用?)”error
这是我的代码:(两个文件都上传到同一个文件夹)
***** WebForm1.asxp ******
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
EmployeeDBContext db = new EmployeeDBContext();
Department Dept = new Department();
Dept = db.Departments.SingleOrDefault(p => p.Id == 1);
Response.Write(Dept.Id);
Response.Write("<br>");
Response.Write(Dept.Name);
Response.Write("<br>");
Response.Write(Dept.Location);
}
}
}
**************** EmployeeDBContext班级************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace WebApplication4
{
public class EmployeeDBContext : DbContext
{
public DbSet<Department> Departments {get; set;}
public DbSet<Employee> Employees { get; set; }
}
}
********部门班.cs ********
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication4
{
public class Department
{
// Scalar Properties
public int Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
// Navigation Property
public List<Employee> Employees { get; set; }
}
}