tags:

views:

147

answers:

1

I am using version 2.1 of SubSonic. I am trying to build to build a relatively simple query where I get a list of Roles for a User using UserId as a parameter. (UserId is a string...)

SubSonic.SqlQuery sel = new SubSonic.Select().From(Data.Tables.Role).InnerJoin(Data.Tables.UserRole, Data.UserRole.Columns.RoleId, Data.Tables.Role, Data.Role.Columns.Id).InnerJoin(Data.Tables.User, Data.User.Columns.Id, Data.Tables.UserRole, Data.UserRole.Columns.UserId).Where("[dbo].[User].[Id]").IsEqualTo(userId);

this generates the query

SELECT [dbo].[Role].[Id], [dbo].[Role].[PID], [dbo].[Role].[Name] FROM [dbo].[Role] INNER JOIN [dbo].[UserRole] ON [dbo].[Role].[Id] = [dbo].[UserRole].[RoleId] INNER JOIN [dbo].[User] ON [dbo].[UserRole].[UserId] = [dbo].[User].[Id] WHERE [dbo].[User].[Id] = @[dbo].[User].[Id]0

which fails. If I replace the Where with .Where(Data.User.Columns.Id) this generates the query

SELECT [dbo].[Role].[Id], [dbo].[Role].[PID], [dbo].[Role].[Name] FROM [dbo].[Role] INNER JOIN [dbo].[UserRole] ON [dbo].[Role].[Id] = [dbo].[UserRole].[RoleId] INNER JOIN [dbo].[User] ON [dbo].[UserRole].[UserId] = [dbo].[User].[Id] WHERE [dbo].[Role].[Id] = @Id0

which uses the Role table in the Where clause instead of the User table.

Is this a bug, or am I doing something incorrectly? What would be the correct way to do this? Thanks.

+1  A: 

This is fixed in version 2.2 - I would suggest upgrading.

Rob Conery
Thanks Rob. That fixed it. It is no longer trying to cast my string ID to an int. (I just started with SubSonic a few days ago, so I still feel like noob.)ps:I just ordered your MVC book on Amazon a few days ago. I can't wait to get it!/flattery
Antoine