我想在我的主屏幕上抛出一堆通知,但是我使用分页来确保我不会在内存中连接2,3或4个查询,这可能有数千个结果。我在编写此查询时遇到一些麻烦,任何指导都将不胜感激......
域模型:我有一堆报告,您可以创建/关闭报告,创建任务并评论与报告相关的任务。
我的查询需要发送:
到目前为止我的代码:
[NonAction]
private IList<NotifcationDTO> GetNotifications(LoggedonuserDTO loggedonuser, int skip, int take)
{
var allreports = _repo.All<Report>();
var alltasks = _repo.All<ReportTask>().Join(allreports ,
x => x.ReportID, y => y.ReportID, (_task, _report) =>
new
{
_report,
_task
})
.Where(x => x._task.CompanyID == loggedonuser.CompanyID || x._task.AssignedToCompanyID == loggedonuser.CompanyID);
var _companies = _repo.All<Company>();
var _users = _repo.All<User>();
var _activities = alltasks.OrderByDescending(o => o._task.DateCreated)
.Select(x => new NotifcationDTO
{
Title = x._report.SubjectPropertyAddress1,
MessageID = x._report.ReportID,
NotificationType = NotificationType.NewTask.ToString(),
Comment = x._task.Title,
Importance = Importance.Medium.ToString(),
Timestamp = x._task.DateCreated,
UserFriendlyName = _users.Where(y => y.UserID == x._task.UserID).FirstOrDefault().Login,
EntityFriendlyName = _companies.Where(y => y.CompanyID == x._task.CompanyID).FirstOrDefault().Identifier
});
return _activities.Skip(skip).Take(take).ToList();
//更新 - 查询以连接到...
var comments = _repo.All<InstructionTaskComment>();
var _taskcomments = alltasks
.Join(comments, x => x._task.TaskID, y => y.TaskID, (_task, _comment) => new
{
_task,
_comment
})
.OrderByDescending(o => o._comment.Timestamp)
.Select(x => new NotifcationDTO
{
Title = x._task._report.SubjectPropertyAddress1,
MessageID = x._task._report.ReportID,
NotificationType = NotificationType.Comment.ToString(),
Comment = x._comment.Comment,
Importance = Importance.Low.ToString(),
Timestamp = x._comment.Timestamp,
UserFriendlyName = _users.Where(y => y.UserID == x._comment.UserID).FirstOrDefault().Login,
EntityFriendlyName = _companies.Where(y => y.CompanyID == x._comment.CompanyID).FirstOrDefault().Identifier
});
}