Select distinct

Posts   
 
    
Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 09-Oct-2007 18:05:20   

Been trying to figure out how to execute the following query using LLBLGen, and it seems like I've hit a mental brick wall...

SELECT DISTINCT [manufactureCode] FROM [Article] INNER JOIN [Vehicle] ON [Article].[V_ID] = [Vehicle].[Id] WHERE [Article].[P_ID] = @p1 AND [Vehicle].[M_ID] = @p2

Any ideas?

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 09-Oct-2007 18:53:27   

This should work:

DataAccessAdapter adapter = new DataAccessAdapter();
ResultsetFields fields = new ResultsetFields(1);
fields.DefineField(ArticleFields.ManufactureCode, 0);
IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(ArticleEntity.Relations.VehicleEntityUsingVId, JoinHint.Inner);

DataTable dynamicList = new DataTable();
adapter.FetchTypedList(fields, dynamicList, bucket, 0, null, false, null);

I'm assuming a few things here: -You are using LLBLGen 2.5 -You are using Adapter -The ManufactureCode field belongs to the Article Table -And of course, the naming of the mapped tables and fields in your project.

Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 12-Oct-2007 12:34:45   

Your assumptions are correct, however.. I don't see the DISTINCT part anywhere?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Oct-2007 12:47:06   

The FetchTypedList method accepts a boolean parameter (allowDuplicates), you should set it to false as the example shown before.

Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 12-Oct-2007 15:23:20   

Ahh, thank you, missed that.

Problem solved =)