I'm using this code to select the row with the Min ProductVersionID and have the problem that the column from the select statement is missing the column name. I tried changing the Alias to be "VersionID" instead of "ProductVersionID" and it works, is it not possible to use the same name as the original column?
public ProductColorsTypedList GetProductColors(int productID)
{
using(WSDataAccessAdapter adapter = new WSDataAccessAdapter(DBUtil.ConnectionString))
{
ProductColorsTypedList colorsList = new ProductColorsTypedList();
IRelationPredicateBucket filter = (IRelationPredicateBucket)colorsList.GetRelationInfo();
filter.PredicateExpression.Add( PredicateFactory.CompareValue(ProductVersionFieldIndex.ActiveState, ComparisonOperator.Equal, ActiveState.Web ) );
//filter.PredicateExpression.Add( PredicateFactory.CompareValue(ProductFieldIndex.ActiveState, ComparisonOperator.Equal, ActiveState.Web) );
filter.PredicateExpression.Add( PredicateFactory.CompareValue(ProductVersionFieldIndex.ProductID, ComparisonOperator.Equal, productID ) );
// Create Group By Clause
ResultsetFields fields = (ResultsetFields)colorsList.GetFieldsInfo();
fields["ProductVersionID"].AggregateFunctionToApply = AggregateFunction.Min;
fields["ProductVersionID"].Alias = "VersionID";
IGroupByCollection groupBy = new GroupByCollection();
for(int i = 0; i < fields.Count; i++)
{
IEntityField2 field = fields[i] as IEntityField2;
// Add all the fields to the group by clause except for
// fields that have an aggregate function applied.
if ( field.AggregateFunctionToApply == AggregateFunction.None )
groupBy.Add(field);
}
adapter.FetchTypedList(colorsList.GetFieldsInfo(), colorsList, filter, 0, null, false, groupBy);
return colorsList;
}
}