Multiple left outer joins - what am I doing wrong

Posts   
 
    
jsspam
User
Posts: 18
Joined: 16-Mar-2012
# Posted on: 14-Jun-2012 02:41:40   

I am trying to do 2 simple outer left joins but am unable to get them to work.

I am using the latest build, self servicing, vb.net

I have tried the following 3 versions of the query which do not work.


      q = From com In lmd.Complaint
           Group Join cus In lmd.CustomerComplaint On com.ComId Equals cus.ComId Into cusgroup = Group
           From c In cusgroup.DefaultIfEmpty()
           Group Join prd In lmd.ComplaintProduct On com.ComId Equals prd.ComId Into prdgroup = Group
             From p In prdgroup.DefaultIfEmpty()
                     Select com.ComId, com.ComDate, .Location = com.Mill,       
       cus.CustomerNo, cus.CustomerName, prd.ProductNo, prd.ProductName

        q = From com In lmd.Complaint
          Join cus In lmd.CustomerComplaint On com.ComId Equals cus.ComId
          Join prd In lmd.ComplaintProduct On prd.ComId Equals com.ComId
                    Select New With {com.ComId, com.ComDate, .Location = com.Mill,      
       cus.CustomerNo, cus.CustomerName, prd.ProductNo, prd.ProductName}

        q = From com In linqCom
        From cus In lmd.CustomerComplaint.Where(Function(x) x.ComId = com.ComId).DefaultIfEmpty()
        From prd In lmd.ComplaintProduct.Where(Function(x) x.ComId = com.ComId).DefaultIfEmpty()
        Select New With {om.ComId, com.ComDate, .Location = com.Mill,       
       cus.CustomerNo, cus.CustomerName, prd.ProductNo, prd.ProductName}


It does not look like its even hitting the db.

The same query from a sql view is

SELECT   dbo.ComplaintProducts.ProductNo, dbo.ComplaintProducts.ProductName, dbo.Complaints.*, dbo.CustomerComplaints.CustomerNo, 
                      dbo.CustomerComplaints.CustomerName
FROM         dbo.Complaints LEFT OUTER JOIN
                      dbo.CustomerComplaints ON dbo.Complaints.ComId = dbo.CustomerComplaints.ComId LEFT OUTER JOIN
                      dbo.ComplaintProducts ON dbo.Complaints.ComId = dbo.ComplaintProducts.ComId

can you tell me what i am doing wrong?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jun-2012 07:54:07   

I don't understand what "Group Join" is. The query should look like:

q = From com In lmd.Complaint
         Join cus In lmd.CustomerComplaint On com.ComId Equals cus.ComId Into cusgroup _
         Join prd In lmd.ComplaintProduct On com.ComId Equals prd.ComId Into prdgroup  _ 
         From c In cusgroup.DefaultIfEmpty() _
         From p In prdgroup.DefaultIfEmpty() _
         Select com.ComId, com.ComDate, Location = com.Mill,  _
         cus.CustomerNo, cus.CustomerName, prd.ProductNo, prd.ProductName

Also you said it never hits the DB with is odd. You need at least enumerate the "q" variable or convert it directly using .ToList:

Dim results = q.ToList();
David Elizondo | LLBLGen Support Team
jsspam
User
Posts: 18
Joined: 16-Mar-2012
# Posted on: 14-Jun-2012 16:26:37   

A plain "Into cusgroup" does not work in vb.net. I get an "end of statement expected" error. http://msdn.microsoft.com/en-us/library/bb531303.aspx http://msdn.microsoft.com/en-us/library/bb763150.aspx

You need at least enumerate the "q" variable or convert it directly using .ToList:

I already am.

???

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jun-2012 19:54:11   

Which "LinqSupport... dll" build (right click, properties, file version). are you using?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 15-Jun-2012 11:26:23   

1) enable DQE tracing (see troubleshooting and debugging in the docs) 2) check whether there are exceptions thrown, so be sure you're not swallowing any exceptions.

I already am.

???

No, in your code you posted, there's no enumerating statement

Frans Bouma | Lead developer LLBLGen Pro