Problem with LINQ query

Posted by Niels Bosma on Stack Overflow See other posts from Stack Overflow or by Niels Bosma
Published on 2009-12-02T09:46:47Z Indexed on 2010/04/05 15:23 UTC
Read the original article Hit count: 236

Filed under:
|

The following works fine:

                    (from e in db.EnquiryAreas
                            from w in db.WorkTypes
                            where
                            w.HumanId != null &&
                            w.SeoPriority > 0 &&
                            e.HumanId != null &&
                            e.SeoPriority > 0 &&
                            db.Enquiries.Where(f => 
                                f.WhereId == e.Id && 
                                f.WhatId == w.Id && 
                                f.EnquiryPublished != null && 
                                f.StatusId != EnquiryMethods.STATUS_INACTIVE &&
                                f.StatusId != EnquiryMethods.STATUS_REMOVED &&
                                f.StatusId != EnquiryMethods.STATUS_REJECTED &&
                                f.StatusId != EnquiryMethods.STATUS_ATTEND
                            ).Any()
                            select
                            new
                            {
                                EnquiryArea = e,
                                WorkType = w
                            });

But:

               (from e in db.EnquiryAreas
                            from w in db.WorkTypes
                            where
                            w.HumanId != null &&
                            w.SeoPriority > 0 &&
                            e.HumanId != null &&
                            e.SeoPriority > 0 &&
                            EnquiryMethods.BlockOnSite(db.Enquiries.Where(f => f.WhereId == e.Id && f.WhatId == w.Id)).Any()
                            select
                            new
                            {
                                EnquiryArea = e,
                                WorkType = w
                            });

+

   public static IQueryable<Enquiry> BlockOnSite(IQueryable<Enquiry> linq)
    {
        return linq.Where(e => 
            e.EnquiryPublished != null && 
            e.StatusId != STATUS_INACTIVE &&
            e.StatusId != STATUS_REMOVED &&
            e.StatusId != STATUS_REJECTED &&
            e.StatusId != STATUS_ATTEND
        );
    }

I get the following error:

base {System.SystemException}: {"Method 'System.Linq.IQueryable1[X.Enquiry] BlockOnSite(System.Linq.IQueryable1[X.Enquiry])' has no supported translation to SQL."}

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#