Generated SQL Query is wrong, why?

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 07-Jul-2005 17:09:45   

Hi,

this is my code:


InfoRegGroupsTypedList InfoRegGroupsList1 = new InfoRegGroupsTypedList();
IPredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareValue(InforegGroupsFieldIndex.Company, ComparisonOperator.Equal, CurrentUser.Company));
filter.Add(PredicateFactory.CompareValue(InforegGroupsFieldIndex.Registry, ComparisonOperator.Equal, "17"));

ISortExpression sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(InforegGroupsFieldIndex.Code, SortOperator.Ascending));

InfoRegGroupsList1.Fill(0, sorter, true, filter);

In the documentation I read that AllowDuplicates should be set to true, so I did that...

In SQL Profiler I get this query:

[code] exec sp_executesql N'SELECT [InfoRegistryGroups].[CODE] AS [Code],[InfoRegistryGroups].[DESCRIPTION] AS [Description] FROM [dbo].[INFOREG_GROUPS] AS [InfoRegistryGroups] WHERE ( [dbo].[INFOREG_GROUPS].[COMPANY] = @Company1 And [dbo].[INFOREG_GROUPS].[REGISTRY] = @Registry2) ORDER BY [dbo].[INFOREG_GROUPS].

 ASC', N'@Company1 varchar(3),@Registry2 varchar(2)', @Company1 = '001', @Registry2 = '17'

This goes wrong because the table is reference as InfoRegistryGroups while it is still using INFOREG_GROUPS as the table for the clause and the sort.

InfoRegistryGroups is the alias that I have given the TypedList in the designer.

Can anybody tell me what I am doing wrong?

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 08-Jul-2005 09:42:20   

Once you give an entity an alias in the TypedList designer, you have to specify that alias in the filters and sortclauses as well. You can do that with an overload of the CompareValue method and the Create method for sortclauses.

You should use aliasses when you add an entity twice to a typed list, otherwise you don't need aliases and to keep your own code more clean, you then just shouldn't use an alias.

Frans Bouma | Lead developer LLBLGen Pro