Select Distinct Field query

Posts   
 
    
_manish
User
Posts: 7
Joined: 27-Feb-2009
# Posted on: 15-Jul-2009 08:26:42   

Suppose my query is :

SELECT DISTINCT Description FROM Table1 WHERE (FKId = 1)

My code of c# is

DataTable listDescription = new DataTable (); IEntityFields2 fields; fields = new EntityFields2(2); fields.DefineField(Table1Fields.Id, 0); fields.DefineField(Table1Fields.Description, 1);

        IRelationPredicateBucket predicate = new RelationPredicateBucket();
        predicate.PredicateExpression.Add(Table1Fields.FKId == 1);
        predicate.Relations.Add(Table1Entity.Relations.TableFKEntityUsingPackageRespondentId, JoinHint.Left);
        m_adapter.FetchTypedList(fields, listRFQ, predicate,false);

        return listRFQ;

Now the things is how to apply distinct on description ??

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Jul-2009 10:22:29   

1- First of all you should use ResultsetFields to define the fields.

ResultsetFields fields = new ResultsetFields( 2 );

2- To apply DISTINCT you should use an overload of the FetchTypedList() method that accepts a boolean parameter (allowDuplicates) and set it to true.

3- Note that DISTINCT always applies to the entire resultSet, you can't pick a field to apply it to. SO you might need to remove the Id field from your resultSet.