IQueryable 在哪里无法工作
我正在使用 N-Hibernate,并且有一个名为 Boxers 的类/表,
我还有一个前景表,它告诉用户拳击手是否是潜在客户。 (这个表只是拳击手ID的一列)
所以我想获取所有有前景的拳击手(意味着所有在前景表中有ID的拳击手)
Public static IQueryable<Boxer> IsProspect(this IQueryable<Boxer> query)
{
return query.Where(x => x.Prospect != null);
}
这不会将我的拳击手列表缩减为有前景的拳击手。然而,如果我调试并查看任何拳击手,每个拳击手旁边都会正确地显示 True 或 false...
为什么 where 子句没有正确地修剪列表?
I am using N-Hibernate and have a class/table called Boxers
I also have a prospect table which tells use if the boxer is a prospect. (this table is one column of just the boxersID)
So i Want to get all boxers that are prospects (meaning all boxers that have there id in the prospects table)
Public static IQueryable<Boxer> IsProspect(this IQueryable<Boxer> query)
{
return query.Where(x => x.Prospect != null);
}
this doesnt trim down my list of boxers to the boxers that are prospect... yet if i debug and look at any boxer it will have True or false next to each one correctly...
Why isnt the where clause correctly trimming down the list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议删除 Prospects 表,并在 Boxers 表中添加一列,名为“IsProspect”,它只是某种布尔值。这将简化您的数据库架构和 NHibernate 映射。
除此之外,检查 x.Prospect 不为 null 将返回所有 Boxer。相反,使用这一行:
只需检查布尔值是否为 true,而不是检查它是否不为 null。
I would recommend getting rid of the prospects table and adding a column to the Boxers table called something like 'IsProspect' that is just a boolean of some sort. This will simplify your database schema and your NHibernate mappings.
Other than that, checking that
x.Prospect
is not null will return allBoxer
s. Instead, use this line:Just check that the boolean value is true, instead of checking that it's not null.