Problem with ObeyWeakRelations and PrefetchPath

Posts   
 
    
Posts: 98
Joined: 10-Nov-2006
# Posted on: 14-Apr-2008 18:26:19   

Observed with 2.5 Final ( March 28th, 2008 ) using SQL Server and SelfServicing:

This is a follow up to the issue: "Issue using Relations.ObeyWeakRelations with PrefetchPath.Add" (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=11903), in which Frans mentioned that the problem with LLBLGen generating incorrect SQL when RelationCollections with ObeyWeakRelations turned on are used with PrefetchPaths could not easily be fixed ....

I understand that the join issue might not be fixable, but the fact that LLBLGen generates bad SQL without any warning is scary. Would it be possible to throw an exception or similar in this situation (where ObeyWeakRelations is set to true on a PrefetchPath call) so that the developer would have some hint about what is wrong? It took me a long time to figure out why my query wasn't getting the correct results, and I'm hoping there's a way for other developers to avoid spending that time. I realize that throwing an Exception when one wasn't thrown before is not likely a change that you'd be willing to make as it might break perfectly fine code, but maybe there's a way to narrow down the issue and only throw an exception if the code is actually about to use an incorrect join?

Thanks,

Wesley

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-Apr-2008 18:55:16   

Rule of thumb: use JoinHint over obeyweakrelations. So if you can: use JoinHint. All generated code uses JoinHint instead of ObeyWeakRelations. So you only run into this issue if: - your relations setup is the one which causes problems. This is an edge case and very hard to determine (if at all, hence the reason it's not fixable) - you set ObeyWeakRelations to true - you require left joins.

You can achieve the query you want with JoinHint. So please use that instead of ObeyWeakRelations, if you use a complex join query with multiple LEFT joins.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 10-Nov-2006
# Posted on: 14-Apr-2008 19:43:07   

Thanks. I'll try to remove my dependence on ObeyWeakRelations.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-Apr-2008 20:41:26   

wesleysmith wrote:

Thanks. I'll try to remove my dependence on ObeyWeakRelations.

To clarify: when we build ObeyWeakRelations, there were no 'JoinHint's. So it seemed more easier to use. However we discovered some edge-case queries which resulted in different SQL than expected. To detect that isn't really doable so we added JoinHint to both fix the problem and give more freedom tot he developer.

Frans Bouma | Lead developer LLBLGen Pro