开发者

IQueryable Where fails to work

I am using N-Hibernate and have a class/table called Boxers

I also have a prospec开发者_如何学JAVAt 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?


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 all Boxers. Instead, use this line:

return query.Where(x => x.Prospect);

Just check that the boolean value is true, instead of checking that it's not null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜