开发者

iqueryable select/where not working

I have two tables Boxer and Prospect. Boxers has general stuff like name and and dob etc and a BoxerId While Prospect contains only one value (at the moment) which is a boxerId. If a boxer is a prospect(up and coming boxer) there Id will be in the prospect table.

This works fine but no开发者_开发知识库w I want to select all boxers that are prospects

    public static IQueryable<Boxer> IsProspect(this IQueryable<Boxer> query)
    {
        //this does not filter down to only prospects!!!
        return query.Where(x => x.Prospect != null);
    }

This is the function I call using:

var repository = GetRepository<Boxer>();
var boxers = repository.Query().IsProspect();

I would hope this would filter my collection of all boxers down to just boxers that are prospects!

Oddly it doesnt filter it but if i hover over my boxers object and look at each boxer during debugging I can see "IsProspect" true or false correctly IsProspect Debug Example http://img534.imageshack.us/img534/4361/isprospect.png


If you want only those objects where IsProspect is true then use that as your predicate:

public static IQueryable<Boxer> IsProspect(this IQueryable<Boxer> query)
{
    return query.Where(x => x.IsProspect);
}


It sounds like you should use table-per-subclass inheritance.


overload a datacontext and directly call the function from your datacontext object

public partial class myDataContext
{
       public IQueryable<Boxer> IsProspect()
       {
             return from tBoxer in myDataContext.tBoxer 
                    where tBoxer.IsProspect == true             
                    select tBoxer;
       }
}

and you would call it like a normal function call like so var db = new myDataConext(); var prospects = db.IsProspect();

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜