tags:

views:

95

answers:

2

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."}

+1  A: 

Linq to Sql only translates certain method calls to SQL, and yours (BlockOnSite) is not one of them. Hence the error. The fact that your method takes an IQueryable<T> and returns an IQueryable<T> doesn't make it special.

bruno conde
+1  A: 

Ok I solved it using:

        IQueryable<Enquiry> visibleOnSite = EnquiryMethods.VisibleOnSite(db.Enquiries);

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