使用 lambda 过滤实体集
所以我的服务器上有这个,
public IQueryable<Pos>GetPos(int programID)
{
var entitySet = _posRepository.All().Where(x => x.ProgramID == programID).Include("RecPositions.Person");
return entitySet.Where(x => x.RecPositions.Any(rp => rp.PosRank != 0));
}
我有类似/相同的吗?客户端上的代码。但我认为这应该在服务器上完成,这样我就不会带回数千条记录。我期望 (rp => rp.PosRank != 0) 省略任何具有 0 的记录...但由于某种原因它不是。有人可以看一下,如果我遗漏了什么,请告诉我。我再次希望所有为 0 的 PosRank 记录不包含在结果集中。
So I have this on the server
public IQueryable<Pos>GetPos(int programID)
{
var entitySet = _posRepository.All().Where(x => x.ProgramID == programID).Include("RecPositions.Person");
return entitySet.Where(x => x.RecPositions.Any(rp => rp.PosRank != 0));
}
I have similar/same? code on the client. But figured this should be done on the server so I dont potentially bring back thousands of records. Im expecting the (rp => rp.PosRank != 0) to omit any records that have a 0...but for some reason it isnt. Can someone take a look and let me know if I am missing something. Again i want all PosRank records that are 0 to not be included in result set.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码当前表示要包含具有非零 PosRank 的任何 RecPositions 的任何实体。
它不会过滤实体中返回的 RecPositions - 它会过滤它们的父类型 (Pos)。
如果您只想包含 Pos 实体,其中所有 RecPositions 都具有非零 PosRank,您只需:
如果您确实想要 RecPosition 值(而不是 Pos 值),您可能需要:
Your code is currently saying to include any entities which have any RecPositions with a non-zero PosRank.
It's not filtering the RecPositions returned within the entities - it's filtering their parent type (Pos).
if you only want to include Pos entities where all the RecPositions have a non-zero PosRank, you simply want:
If you really want the RecPosition values (instead of the Pos values), you might want: