Lets say I have a view called vwEmployees that has two fields (SupervisorID, EmployeeID) and contains the following data:
SupervisorID EmployeeID
1 100
2 100
3 101
4 101
I also have a GridView called gvEmployees and a LlblGenProDataSource called dsEmployees. In the gvEmployees_DataBinding event handler, I set:
dsEmployees.DataContainerType = "EntityCollection";
dsEmployees.EntityCollectionTypeName = "MyProj.LLBLGen.CollectionClasses.VwEmployeesCollection, MyProj.LLBLGen";
dsEmployees.Select();
gvEmployees.DataSource = dsEmployees;
The code above results in the GridView having 4 records, as expected. However, I need a way to SELECT DISTINCT EmployeeID FROM vwEmployees (or from dsEmployees itself) so that the resulting dsEmployees would only contain 2 records, for example:
SupervisorID EmployeeID
1 100
3 101
I don't care whether or not the SupervisorID column is included in dsEmployees. However, the issue is that I don't want to change the view's definition (such as removing the SupervisorID column from the schema) because this view is being used in other parts of my application where the SupervisorID column is used for filtering. Also, I'm trying to avoid creating a duplicate view but without the SupervisorID column.
It would be easy if I can loop through each item in dsEmployees and remove the entries with duplicate EmployeeIDs. But I can't seem to find a way to iterate through the dsEmployees.
I tried this code:
ArrayList arDistinctEmployeeIDs = new ArrayList();
foreach (VwEmployeesEntity entity in dsEmployees.EntityCollection)
{
if (!arDistinctEmployeeIDs.Contains(entity.EmployeeID))
{
arDistinctEmployeeIDs.Add(entity.EmployeeID);
}
else
{
dsEmployees.EntityCollection.Remove(entity);
}
}
gvEmployees.DataSource = dsEmployees;
...but it gave me an error...
Any help is greatly appeciated. Thanks.