使用MVC3,我有一个学生仓库(在一个项目中)和一个StudentService(在另一个项目中)。在服务中,我想创建一个函数,该函数返回数据库表中的所有学生。这对我来说是一种新的做法,所以我有点陌生。在下面的GetAllStudents函数中,我应该如何更改语法以选择全部。
在仓库中:
在仓库中:
namespace SpeakOut.Data
{
public class StudentRepository
{
SpeakOutDataContext context;
private Table<StudentEntity> table;
public StudentRepository()
{
context = new SpeakOutDataContext();
table = context.GetTable<StudentEntity>();
}
public IQueryable<Student> Select()
{
return table.Select(x => new Student
{
WNumber = x.WNumber,
CatalogueYear = x.CatalogueYear,
Standing = x.Standing
});
}
}
在服务中:
namespace SpeakOut.Services
{
public class StudentService
{
private StudentRepository repository;
public StudentService()
{
repository = new StudentRepository();
}
public IQueryable<Student> GetAllStudents()
{
return repository.Select().All(x => x.FirstName) ; //**This line is where I don't know how I would call all the students**
}
}
}