tags:

views:

37

answers:

1

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?

A: 

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.

Aaron
i would prefere not to put the prospect into the table as it isn't the same thingyour line of code (moving the "!= null") fails as cannot do a object of Prospect == bool
Steve
@Steve I think Aaron is assuming (and this is how I read it, too) that `x.Prospect` is a `bool` property of `Boxer`. This is also why your method returns all of the `Boxer` objects -- neither `true` nor `false` is `null`.
Jay
Aaron
the prospect object is currently only a list of boxerid (but there will be more fields in it in future) there isnt any boolean on the prospect table.
Steve
If there is no boolean, then what do you mean by this? "yet if i debug and look at any boxer it will have True or false next to each one correctly"
Aaron