JoinHint's being ignored

Posts   
 
    
reprezent
User
Posts: 11
Joined: 17-Feb-2007
# Posted on: 24-Oct-2007 06:29:25   

OK, this is probably an easy one for most of you but I'm stumped. I'm using 2.0 adapter and I'm having trouble getting LLBL to obey the join hints I'm telling it to use in order to create the query I need. Instead of using left joins for all, it is switching some to right joins, which is causing the query to return no results.

Here are the tables used in the query and how they are related:

Order -> Cart = m:1
OrderItem -> Order = m:1
Product -> OrderItem = 1:n
Supplier -> Product = 1:n
Person -> Cart = 1:n

Here is the query I am trying to create; note it uses all left joins and selects from the Order table:

SELECT DISTINCT o.ID, s.Name
FROM Order o
LEFT JOIN Cart c on c.ID = o.CartID
LEFT JOIN OrderItem i on o.ID = i.OrderID
LEFT JOIN Product p on i.ProductID = p.ID
LEFT JOIN Supplier s on p.SupplierID = s.ID
LEFT JOIN Person n on n.ID = c.PersonID
WHERE o.ResponseCode = 1 AND n.ID = 12343

So I run the following code:


Dim fields As New ResultsetFields(2)
fields.DefineField(OrderFields.Id, 0)
fields.DefineField(SupplierFields.Name, 1)

Dim filter As New RelationPredicateBucket
filter.Relations.ObeyWeakRelations = True
filter.Relations.Add(CartEntity.Relations.OrderEntityUsingCartId, JoinHint.Left)
filter.Relations.Add(OrderItemEntity.Relations.OrderEntityUsingOrderId, JoinHint.Left)
filter.Relations.Add(ProductEntity.Relations.OrderItemEntityUsingProductId, JoinHint.Left)
Filter.Relations.Add(SupplierEntity.Relations.ProductEntityUsingSupplierId, JoinHint.Left)
Filter.Relations.Add(PersonEntity.Relations.CartEntityUsingPersonId, JoinHint.Left)
Filter.PredicateExpression.Add(OrderFields.ResponseCode = 1)
Filter.PredicateExpression.Add(PersonFields.Id = myUserID)

Dim sort As New SortExpression
sort.Add(New SortClause(OrderFields.DateFinished, Nothing, SortOperator.Descending))

Dim dt As New DataTable
Using adapter As New DataAccessAdapter(myConnStr, True)
         adapter.FetchTypedList(fields, dt, filter, 0, sort, False)
End Using

This is giving me the following query; note LLBL has changed some of the joins to right joins and the select is now from the Cart table:

SELECT DISTINCT o.ID, s.Name
FROM Cart c
RIGHT JOIN Order o on c.ID = o.CartID
LEFT JOIN OrderItem i on o.ID = i.OrderID
LEFT JOIN Product p on i.ProductID = p.ID
RIGHT JOIN Supplier s on p.SupplierID = s.ID
RIGHT JOIN Person n on n.ID = c.PersonID
WHERE o.ResponseCode = 1 AND n.ID = 12343

I tried it with and without the ObeyWeakRelations property. I also tried rearranging the order of the join statements. It always seems to come up the same way. What am I doing wrong?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Oct-2007 11:16:03   

Which LLBLGen Pro runtime library version are you using?

reprezent
User
Posts: 11
Joined: 17-Feb-2007
# Posted on: 24-Oct-2007 15:05:38   

Walaa wrote:

Which LLBLGen Pro runtime library version are you using?

2.0.0.0 Final, adapter method

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Oct-2007 16:42:45   

That's not a correct runtime library version. Please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722

reprezent
User
Posts: 11
Joined: 17-Feb-2007
# Posted on: 25-Oct-2007 04:19:37   

Walaa wrote:

That's not a correct runtime library version. Please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722

My mistake, 2.0.0.61205

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Oct-2007 12:24:49   

ObeyWeakRelations is one way to specify left/right joins: let the system figure it out. However if you want fine grained control, you can specify join hints and should leave ObeyWeakRelations to false as they can't be used together.

ObeyWeakRelations was added as a convenience method a long time ago so people didn't have to specify the join direction per se. However in some situations it could give odd results, so we added the join hints as well, which are more precise. ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9511