"correlation" names ?

Posts   
 
    
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 02-Dec-2005 12:08:11   

I have the following situation. In my program i have a search screen, in which the user can type values for the searchfilter. In one particular case, he can (partially) enter the name of a "supplier", so my "reception"list will be filtered. But there is a catch, a "reception" can be "open", and then it has a direct link to a supllier, or it can be bound to a contract, and then the link to the supplier is in the contract. So when the user types in a suppliername i have to filter all recepetions linked to this supplier, either directly or via a contract. The code i use for this filter is :


                ReceptionCollection rcoll = new ReceptionCollection();
                RelationCollection rc = new RelationCollection();
                PredicateExpression pe = new PredicateExpression();
                string filter;

// ... do some other filters here

                filter = txtLeverancier_nt.Text;
                if (filter!="")
                {
                    //do it for both contract & free reception
                    rc.Add(ReceptionEntity.Relations.SupplierEntityUsingSupId,JoinHint.Left);
                    rc.Add(ReceptionEntity.Relations.ContractEntityUsingCId,JoinHint.Left);
                    rc.Add(ContractEntity.Relations.SupplierEntityUsingSupId,JoinHint.Left);
                    PredicateExpression subfilter = new PredicateExpression();
                    subfilter.Add(PredicateFactory.Like(SupplierFieldIndex.SupLastname,"%"+filter+"%"));
                    subfilter.AddWithOr(PredicateFactory.Like(SupplierFieldIndex.SupFirstname,"%"+filter+"%"));
                    pe.Add(subfilter);//add it in the "main filter"
                }

//do some other filter here and then the query 


                SortExpression sorter = new SortExpression(SortClauseFactory.Create(ReceptionFieldIndex.RecId,SortOperator.Descending));
                rcoll.GetMulti(pe,Shared.MaxSearchResults,sorter,rc,pp);//pp is prefetchpath

The moment i type somthing to filter for the name i get the exception


An exception was caught during the execution of a retrieval query: Tables or functions 'dbo.CONTRACT' and 'dbo.CONTRACT' have the same exposed names. Use correlation names to distinguish them.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

The query executed at this time is :


Query: SELECT DISTINCT TOP 15 [dbo].[RECEPTION].[REC_ID] AS [RecId],[dbo].[RECEPTION].[REC_DATE] AS [RecDate],[dbo].[RECEPTION].[C_ID] AS [CId],[dbo].[RECEPTION].[REC_TRANSPORT_ID] AS [RecTransportId],[dbo].[RECEPTION].[REC_LOONWERK_ID] AS [RecLoonwerkId],[dbo].[RECEPTION].[REC_WB1] AS [RecWb1],[dbo].[RECEPTION].[REC_WB2] AS [RecWb2],[dbo].[RECEPTION].[REC_SAMPLE] AS [RecSample],[dbo].[RECEPTION].[REC_SAMPLEFILE] AS [RecSamplefile],[dbo].[RECEPTION].[REC_REMARK] AS [RecRemark],[dbo].[RECEPTION].[BORD_ID] AS [BordId],[dbo].[RECEPTION].[AR_ID] AS [ArId],[dbo].[RECEPTION].[REC_BEREKENBAAR] AS [RecBerekenbaar],[dbo].[RECEPTION].[REC_FINISHED] AS [RecFinished],[dbo].[RECEPTION].[COMP_ID] AS [CompId],[dbo].[RECEPTION].[STATE_ID] AS [StateId],[dbo].[RECEPTION].[REC_LOT] AS [RecLot],[dbo].[RECEPTION].[SUP_ID] AS [SupId],[dbo].[RECEPTION].[REC_TRANSPORT] AS [RecTransport],[dbo].[RECEPTION].[REC_DEDUCTION] AS [RecDeduction] FROM (((( [dbo].[CONTRACT]  RIGHT JOIN [dbo].[RECEPTION]  ON  [dbo].[CONTRACT].[C_ID]=[dbo].[RECEPTION].[C_ID]) LEFT JOIN [dbo].[RECEPTION_PERCEEL]  ON  [dbo].[RECEPTION].[REC_ID]=[dbo].[RECEPTION_PERCEEL].[REC_ID]) LEFT JOIN [dbo].[SUPPLIER]  ON  [dbo].[SUPPLIER].[SUP_ID]=[dbo].[RECEPTION].[SUP_ID]) RIGHT JOIN [dbo].[CONTRACT]  ON  [dbo].[SUPPLIER].[SUP_ID]=[dbo].[CONTRACT].[SUP_ID]) WHERE ( ( [dbo].[SUPPLIER].[SUP_LASTNAME] LIKE @SupLastname1 Or [dbo].[SUPPLIER].[SUP_FIRSTNAME] LIKE @SupFirstname2)) ORDER BY [dbo].[RECEPTION].[REC_ID] DESC\
Parameter: @SupLastname1 : AnsiString. Length: 4. Precision: 0. Scale: 0. Direction: Input. Value: %pu%.
Parameter: @SupFirstname2 : AnsiString. Length: 4. Precision: 0. Scale: 0. Direction: Input. Value: %pu%.

I have searched in the LLBLGen manual for "correlation" but couldn't find anything... How can i properly alias my tablenames ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Dec-2005 15:35:54   

As you see from the generated SQL Script, you have Entities(Tables) that are mentioned more than once in the From clause. These tables need to be properly aliased.

You should specify aliases for entities when adding relations to the relation collection. The RelationCollection.Add() function have overloads that accept an alias string for the entity.

And if you are going to use those aliased entities in your filter claue (WHERE) you should also use their aliases (objectalias) in the filters. The IPredicate classes (such as FieldLikePredicate & FieldCompareValuePredicate) have constructors that accepts objectalias string in the parameters.

HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 02-Dec-2005 20:23:37   

D'oh i completely overlooked the possiblity to alias like this !

It works like a charm now, thanx !