A DefaultIfEmpty call can't be converted to SQL due to the lack of a predicate or filter to combine lett side with right side.

Posts   
 
    
webbsk
User
Posts: 17
Joined: 24-Sep-2009
# Posted on: 17-Nov-2011 15:37:51   

I am trying to run the following query:

               IQueryable<ProvisioningQueueView> query = (from pq in metaData.ProvisioningQueue
                                                             from pat in metaData.ProvisioningActionTypes.Where(actionType => actionType.Id == pq.ProvisioningActionTypeId).DefaultIfEmpty()
                                                             join prt in metaData.ProvisioningRequestTypes
                                                                 on pq.ProvisioningRequestTypeId equals prt.Id
                                                             join pst in metaData.ProvisioningStatusTypes
                                                                 on pq.ProvisioningStatusTypeId equals pst.Id
                                                             select new ProvisioningQueueView
                                                                        {
                                                                            Id = pq.Id,
                                                                            MerchantId = pq.MerchantId,
                                                                            PrivateLabelId = pq.PrivateLabelId,
                                                                            Action = pat.Description ?? string.Empty,
                                                                            DomainName = pq.DomainName,
                                                                            ExternalIp = pq.ExternalIpAddress,
                                                                            ProcessDate = pq.ProcessDate,
                                                                            Request = prt.Description,
                                                                            Status = pst.Description,
                                                                            StoreId = pq.StoreId
                                                                        });

However, I receive the following error as a result:

A DefaultIfEmpty() call was found on an entity typed sequence as one side of a join. However, the behavior of the DefaultIfEmpty can't be converted to SQL due to the lack of a predicate or filter to combine left side with right side.

I don't understand what's going on because when I run this in Linqpad as Linq to SQL it works perfectly.

Ultimately, what I need to do is a left join with ProvisioningActionTypes and set the default value to the empty string if the value coming in from that table is null. I thought I could do that with the above query, but LLBLGen doesn't seem to support that.

Does anyone have some suggestion as to what to try instead?

webbsk
User
Posts: 17
Joined: 24-Sep-2009
# Posted on: 17-Nov-2011 18:23:09   

I have figured out my own answer:

(from pq in metaData.ProvisioningQueue
                             join pat in metaData.ProvisioningActionTypes
                                on pq.ProvisioningActionTypeId equals pat.Id into pqpat
                             from pat in pqpat.DefaultIfEmpty()
                                join prt in metaData.ProvisioningRequestTypes
                                    on pq.ProvisioningRequestTypeId equals prt.Id
                                join pst in metaData.ProvisioningStatusTypes
                                    on pq.ProvisioningStatusTypeId equals pst.Id
                               select new ProvisioningQueueView
                               {
                                   Id = pq.Id,
                                   MerchantId = pq.MerchantId,
                                   PrivateLabelId = pq.PrivateLabelId,
                                   Action = pat.Description ?? string.Empty,
                                   DomainName = pq.DomainName,
                                   ExternalIp = pq.ExternalIpAddress,
                                   ProcessDate = pq.ProcessDate,
                                   Request = prt.Description,
                                   Status = pst.Description,
                                   StoreId = pq.StoreId
                               })

The reasoning behind it came from Frans post: http://weblogs.asp.net/fbouma/archive/2007/09/11/developing-linq-to-llblgen-pro-day-0.aspx.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 18-Nov-2011 10:53:12   

Also make sure you have the latest build of the runtime version you're using. DefaultIfEmpty() is a painful statement to handle in a linq provider, and we had, unfortunately, a lot of fixes in that area during the past 3 years.

Frans Bouma | Lead developer LLBLGen Pro