我的ASP.NET MVC项目没有检索我的SQL Server Express值

时间:2014-08-27 13:54:58

标签: c# sql asp.net-mvc asp.net-mvc-4

我是ASP.NET MVC的新手,我目前在查找我在web.config文件中指定的SQL Server数据库中的值时出现问题,基本上我创建了一个具有{{{ 1}}和Employee类和Department具有IDepartmentDataIQueryable<Employee>

的界面

以下是我的课程的样子:

IQueryable<Department>

这是我的iInterface:

namespace e.Manager.Data
{
    public class Department
    {
        public int Id { set; get; }
        public string Name { get; set; }
        public ICollection<Employee> Employees { get; set; } 
    }
}

namespace e.Manager.Data
{
    [Table("Person")]
    public class Employee
    {
        public virtual int Id { set; get; }
        public virtual string Name { set; get; }
    }
}

当然我在ASP.NET MVC Web项目中引用了这个项目。

这是我的班级namespace e.Manager.Data { public interface IDepartmentData { IQueryable<Employee> Employees { get; } IQueryable<Department> Departments { get; } } }

DepartmentDb

这是我的连接字符串:

namespace eManager.Web.Infrastructure
{
    public class DepartmentDb : DbContext, IDepartmentData
    {
       public DbSet<Employee> Employees { set; get; }
       public  DbSet<Department> Departments { set; get; }

       IQueryable<Employee> IDepartmentData.Employees
       {
            get { return Employees; }
       }

       IQueryable<Department> IDepartmentData.Departments
       {
            get { return Departments; }
       }
    }
}

我的表格包含相关表格<connectionStrings> <add name="DepartmentDb" connectionString="database=sample;server=CON0389\SQLEXPRESS; Integrated Security=SSPI" providerName="System.Data.SqlClient"/> </connectionStrings> Person

这是我的索引操作方法:

Department

但是我的索引没有检索数据库中的值是不是我在这里做错了什么?提前谢谢你们。

1 个答案:

答案 0 :(得分:0)

谢谢你们的回答我已经弄清楚我的项目出了什么问题,问题是我没有将我的对象映射到我的SQL中的表格,这就是为什么计数返回0 。