我有这些课程:
public class Project
{
public int ProjectId { get; set; }
public int AccountId { get; set; }
public int UserId { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public string Description { get; set; }
public string Tags { get; set; }
public virtual List<Task> Tasks { get; set; }
}
public class Task
{
public int TaskId { get; set; }
public int ProjectId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime StartDate { get; set; }
public DateTime? DueDate { get; set; }
public int TaskOwnerId { get; set; }
public string Tags { get; set; }
public virtual Project Project { get; set; }
public virtual List<TaskAssigned> TaskAssigns { get; set; }
public virtual List<TaskComment> TaskComments { get; set; }
}
public class TaskAssigned
{
public int TaskAssignedId { get; set; }
public int TaskId { get; set; }
public int UserId { get; set; }
}
我需要根据分配给他/她的任务来处理属于每个用户的所有项目我已经提出了这个解决方案,但我无法继续前进:
public List<Project> GetProjectsByAccountIdUserId(int accountId, int userId)
{
var tasks = context.TaskAssigns.Where(ta => ta.UserId == userId).ToList();
var projects =context.Projects.Where(p => p.AccountId == accountId).Include("Tasks").ToList();
return projects;
}
我不知道如何通过 taskId 关联和过滤每个项目的任务。