Generating bad SQL

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 31-Mar-2008 04:12:54   

I have a simple (and probably common) set of tables

User UserRole Role

Linked up like so: User.UserId > UserRole.UserId UserRole.RoleId > Role.RoleId

This means I get a prefetch from UserEntity called PrefetchPathRoleCollectionViaUserRole. If I use this prefetch I get:

**The multi-part identifier "ToxicBeats.dbo.User.UserId" could not be bound. **

Infact I get a similar error if i user ANY "Via" type prefetch mapped on the many to many pattern.

Here is the offending generated SQL:


exec sp_executesql N'SELECT DISTINCT [ToxicBeats].[dbo].[User].[UserId] AS [UserId0], [ToxicBeats].[dbo].[Role].[RoleId] AS [RoleId1] FROM (( [ToxicBeats].[dbo].[User] [LPA_U1]  INNER JOIN [ToxicBeats].[dbo].[UserRole] 
[LPA_U2]  ON  [LPA_U1].[UserId]=[LPA_U2].[UserId]) INNER JOIN [ToxicBeats].[dbo].[Role]  ON  [ToxicBeats].[dbo].[Role].[RoleId]=[LPA_U2].[RoleId]) WHERE ( ( ( ( [LPA_U2].[UserId] = @UserId1))))',N'@UserId1 
int',@UserId1=1

So the User table is assigned an alias and then that alias is not being used in the select list.

Here is what it should look like (well... this runs exception free):


exec sp_executesql N'SELECT DISTINCT [LPA_U1] .[UserId] AS [UserId0], [ToxicBeats].[dbo].[Role].[RoleId] AS [RoleId1] FROM (( [ToxicBeats].[dbo].[User] [LPA_U1]  INNER JOIN [ToxicBeats].[dbo].[UserRole] 
[LPA_U2]  ON  [LPA_U1].[UserId]=[LPA_U2].[UserId]) INNER JOIN [ToxicBeats].[dbo].[Role]  ON  [ToxicBeats].[dbo].[Role].[RoleId]=[LPA_U2].[RoleId]) WHERE ( ( ( ( [LPA_U2].[UserId] = @UserId1))))',N'@UserId1 
int',@UserId1=1

Strangely, a member of my team says he is not having the same issue (same db, different instance) in his environment.

Any ideas?

Heres the complete codeblock that is throwing the error:


PrefetchPath2 path = new PrefetchPath2(EntityType.UserEntity);
        path.Add(UserEntity.PrefetchPathRoleCollectionViaUserRole);

        //To get user's artist information.
        path.Add(UserEntity.PrefetchPathArtistUsingUserId);

        UserEntity user = new UserEntity();
        user.Username = Username.Text.Trim();

        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            PredicateExpression predicate = new PredicateExpression();
            predicate.Add(user.ConstructFilterForUCUsername());
            predicate.AddWithAnd(UserFields.IsActive == true);
            adapter.FetchEntityUsingUniqueConstraint(user, predicate, path);//exception thrown here
        }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Mar-2008 11:19:46   

Mayeb you are using an old runtime library. Which LLBLGen Pro runtime library version are you using?

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 01-Apr-2008 02:38:19   

Hi Walaa,

my DAL is referencing SD.LLBLGenPro.DQE.SqlServer.Net20 Version: 2.5.0.0 (you guys could make better use of version numbers)

Details tab in win explorer says: File version 2.5.7.906 Product version 2.5.07.0906

I will update to the latest and greatest and see if that helps smile

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 01-Apr-2008 03:03:56   

Ok I've updated and it seems to have fixed the problem. Thanks