【发布时间】:2014-07-02 15:07:36
【问题描述】:
我有 DAL、BLL 和 Web 项目。我应该在哪里使用 ToList() 执行查询?
现在我在控制器中使用 ToList() 执行查询 - 可以吗?例如 - 从头开始:
DAL - 我在 NotesRepository 类中的方法:
public IQueryable<Notes> GetAllNotes()
{
return context.Notes.Include(x => x.Comments).OrderByDescending(x => x.CreateDate);
}
BLL - 我在 NotesService 类中的方法:
public IEnumerable<Notes> GetNotes()
{
return _unitOfWork.NotesRepository.GetAllNotes();
}
Web - 我在控制器中的操作(使用 ToList() 执行查询):
public ActionResult Index()
{
var notes = _notesService.GetNotes().ToList();
return View(notes);
}
【问题讨论】:
标签: asp.net-mvc n-tier-architecture