使用MVC3,我有一個Student Repository(在一個項目中)和一個StudentService(在另一個項目中)。在服務中,我想創建一個返回db表中所有學生的函數。這是一種爲我做事情的新方式,所以我有點新。在下面的GetAllStudents函數中,我如何更改語法來選擇全部。如何選擇全部使用IQueryable
在存儲庫:
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**
}
}
}
哦,等等爲什麼我不能說只是返回repositry.Select() – TMan 2012-02-20 17:06:12