Export to GitHub

subsonicproject - issue #109

SQL Query with INNERJOIN with same column names on 2 tables in WHERE


Posted on Aug 18, 2009 by Happy Monkey

Which version are you using (2.x or 3.0)? 2.1 What steps will reproduce the problem? 1.Create SQLQuery for returning a collection 2.Inner join between 2 tables with same column name i.e. StatusFlag ---CODE SAMPLE--- Tat_CityCollection myTat_CityCollection; SubSonic.SqlQuery q;

q = new Select() .From(Tat_City.Schema) .InnerJoin(Tat_AdminArea.Schema) .Where(Tat_AdminArea.CountryIDColumn.ColumnName).IsEqualTo(Id) .And(Tat_City.StatusFlagColumn.ColumnName).IsEqualTo("A") .And(Tat_AdminArea.StatusFlagColumn.ColumnName).IsEqualTo("A");

myTat_CityCollection = q.ExecuteAsCollection<Tat_CityCollection>();

---GENERATED QUERY--- {SELECT [dbo].[Tat_City].[ID], [dbo].[Tat_City].[StatusFlag], [dbo].[Tat_City].[DateCreated], [dbo].[Tat_City].[DateUpdated], [dbo].[Tat_City].[AdminAreaID], [dbo].[Tat_City].[Name], [dbo].[Tat_City].[Lat], [dbo].[Tat_City].[Lon]

FROM [dbo].[Tat_City] INNER JOIN [dbo].[Tat_AdminArea] ON [dbo].[Tat_City].[AdminAreaID] = [dbo].[Tat_AdminArea].[ID] WHERE CountryID = @CountryID0 AND [dbo].[Tat_City].[StatusFlag] = @StatusFlag1 AND [dbo].[Tat_City].[StatusFlag] = @StatusFlag2 } * NOTE '[Tat_City]' twice instead of having '[Tat_AdminArea]'

What is the expected output? What do you see instead?

AND [dbo].[Tat_AdminArea].[StatusFlag] = @StatusFlag2

Would expect the generated where clause to qualify column 'StatusFlag' by table, however generated code has same table name on where clause.

What version of the product are you using? On what operating system? SubSonic 2.1 or 2.2 Development Computer: Windows XP

Northwind Unit Test to verify the problem:

Status: New

Labels:
Type-Defect Priority-Medium