RIA 服务和 lambda JOIN 出现问题
注意:这已在下面的评论中重复回答。
我无法让 RIA 服务返回我需要的数据,但返回的数据不能超过我需要的数据。我有一个父对象(项目),其中包含许多子对象。一个是组件(每个项目一个组件)。另一个是ProjectParticipant,需要根据ParticipantRole进行限制,我还需要抓取Person信息(与ProjectParticipant相关)。
这是我之前尝试过的一些代码:
public IQueryable<IMSModel.Project> GetProjectHierarchy(String id)
{
return this.ObjectContext.Projects
.Include("Component")
.Include("ProjectParticipants")
.Include("ProjectParticipants.Person")
.Where(p => p.Program.ProgramType.lookupName == "EVDBE" &&
p.ProjectOrgs.Any(po => po.orgId == id) &&
p.ProjectParticipants.Any(pp => (pp.postId == id)) &&
p.ProjectParticipants.Any(pp => pp.PersonStatus.lookupName == "A") &&
p.ProjectParticipants.Any(pp => pp.ParticipantRole.participantInd == "Y"))
.OrderBy(p => new { p.fiscalYear, p.title })
.OrderByDescending(p => p.fiscalYear);
}
这工作得还不错,但我最终得到了我不想要的 ProjectParticipant 对象。我真正想做的是将 ProjectParticipant 对象限制为具有 ParticipantRole.participantInd == "Y" 的对象。
我为此尝试了另一种可能的语法,如下所示:
public IQueryable<IMSModel.Project> GetProjectHierarchy(String id)
{
return this.ObjectContext.Projects
.Include("Component")
.Join(this.ObjectContext.ProjectParticipants
.Include("ProjectParticipants.Person")
.Where(
pp => pp.ParticipantRole.participantInd == "Y" &&
pp.postId == id &&
pp.PersonStatus.lookupName == "A"
)
, p => p.id
, pp => pp.projectId
, (p, pp) => p )
.Where(p => p.Program.ProgramType.lookupName == "EVDBE"
&& p.ProjectOrgs.Any(po => po.orgId == id));
}
我认为这会返回更接近我想要的东西。唯一的问题是我在分层树视图中没有得到任何信息。返回了一些内容,因为为每个记录创建了空白位置,但我的绑定没有显示任何信息。第一个示例的绑定确实显示数据,而第二个示例的绑定(结果集更有限,因为我没有使用 Any())不显示数据。
我已经为这个问题苦苦挣扎有一段时间了,但无法解决。任何帮助都会很棒。
NOTE: This has been answered as duplicate in the comment below.
I am having trouble getting RIA Services to return the data I need and not more than the data I need. I have a parent object (Project) which contains a number of children. One is a Component (one Component per Project). Another is a ProjectParticipant which needs to be limited based on the ParticipantRole, and I also need to grab the Person information (related to ProjectParticipant).
Here is some code I had earlier tried:
public IQueryable<IMSModel.Project> GetProjectHierarchy(String id)
{
return this.ObjectContext.Projects
.Include("Component")
.Include("ProjectParticipants")
.Include("ProjectParticipants.Person")
.Where(p => p.Program.ProgramType.lookupName == "EVDBE" &&
p.ProjectOrgs.Any(po => po.orgId == id) &&
p.ProjectParticipants.Any(pp => (pp.postId == id)) &&
p.ProjectParticipants.Any(pp => pp.PersonStatus.lookupName == "A") &&
p.ProjectParticipants.Any(pp => pp.ParticipantRole.participantInd == "Y"))
.OrderBy(p => new { p.fiscalYear, p.title })
.OrderByDescending(p => p.fiscalYear);
}
This doesn't work too badly, but I end up getting ProjectParticipant objects that I do not want. What I really want to do is limit the ProjectParticipant objects to those that have ParticipantRole.participantInd == "Y".
I tried another possible syntax for this, which is as follows:
public IQueryable<IMSModel.Project> GetProjectHierarchy(String id)
{
return this.ObjectContext.Projects
.Include("Component")
.Join(this.ObjectContext.ProjectParticipants
.Include("ProjectParticipants.Person")
.Where(
pp => pp.ParticipantRole.participantInd == "Y" &&
pp.postId == id &&
pp.PersonStatus.lookupName == "A"
)
, p => p.id
, pp => pp.projectId
, (p, pp) => p )
.Where(p => p.Program.ProgramType.lookupName == "EVDBE"
&& p.ProjectOrgs.Any(po => po.orgId == id));
}
I would think that this would return something a lot closer to what I might want. The only issue is that I don't get anything back in my hierarchical tree view. Something was returned, as blank locations were created for each record, but my bindings are not displaying any information. The bindings for the first example do show data, whereas the bindings for the second (more limited result set as I am not using Any()) does not show data.
I have been banging my head against this one for quite some time now and cannot resolve. Any assistance would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论