我有以下实体关系。我想通过传递项目 ID 来过滤资源。
项目类
public class Project : EntityBase
{
public Project()
{
this.Tasks = new HashSet<Task>();
}
[Key]
public Guid GUID { get; set; }
public virtual ICollection<Task> Tasks { get; set; }
}
任务类
public class Task : IIdentifier
{
public Task()
{
this.Assignments = new HashSet<Assignment>();
}
[Key]
public Guid GUID { get; set; }
[ForeignKey("Projects")]
public Guid? ProjectId { get; set; }
public virtual Project Projects { get; set; }
public virtual ICollection<Assignment> Assignments { get; set; }
}
资源类
public class Resource : IIdentifier
{
public Resource()
{
this.Assignments = new HashSet<Assignment>();
}
[Key]
public Guid GUID { get; set; }
public virtual ICollection<Assignment> Assignments { get; set; }
}
作业类
public class Assignment : IIdentifier
{
[Key]
public Guid GUID { get; set; }
[ForeignKey("Tasks")]
public Guid TaskId { get; set; }
public virtual Task Tasks { get; set; }
[ForeignKey("Resources")]
public Guid ResourceId { get; set; }
public virtual Resource Resources { get; set; }
}
现在我想在传递项目 GUID 时获取所有资源
public IEnumerable<Resource> GetResourcesForViewsByProjectId(Guid ProjectId)
{
var x = from t in Uow.Tasks.GetAll().Where(con => con.ProjectId == ProjectId)
from a in Uow.Assignments.GetAll().Where(c => c.TaskId == t.GUID)
from r in Uow.Resources.GetAll()
.Where(r => r.Assignments.Where(con => con.ResourceId == r.GUID))
.DefaultIfEmpty()
select r;
return x;
}
但这不起作用。有什么建议么?