I am querying a table called STUDENT.I want to retrieve 2 values, the STUDENT_ID, and the TIME (Both are strings). However, I only want the distinct values of STUDENT_ID. When I use Distinct() with only STUDENT_ID, I do get unique values. But the moment I include TIME, all the values show up because the times in the table are all different. I also tried to make my own Comparer class, and pass an instance to Distinct().
public class MyCompare : IEqualityComparer<IQueryable>
{
public bool Equals(DataRow x, DataRow y)
{
return (x.Field<string>("STUDENT_ID") == y.Field<string>("STUDENT_ID"));
}
public int GetHashCode(DataRow obj)
{
return obj.ToString().GetHashCode();
}
}
However, I get 4 errors.
1). Is there a way to use distinct on 2 values? ( Since it does sort if it's just STUDENT_ID) I want it to show the unique values for STUDENT_ID and show the corresponding TIMES.
OR.. 2. How do I make a working Comparer? I get the following errors.
a. Error 1 'System.Linq.IQueryable' does not contain a definition for 'Distinct' and the best extension method overload 'System.Linq.ParallelEnumerable.Distinct(System.Linq.ParallelQuery, System.Collections.Generic.IEqualityComparer)' has some invalid arguments C:\Users\KC\Desktop\SoulScanner\SoulScanner\SearchByTime.xaml.cs 360 23 SoulScanner
b. Error 4 Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Linq.IQueryable' C:\Users\KC\Desktop\SoulScanner\SoulScanner\SearchByTime.xaml.cs 363 43 SoulScanner
c. Error 2 Instance argument: cannot convert from 'System.Linq.IQueryable' to 'System.Linq.ParallelQuery' C:\Users\KC\Desktop\SoulScanner\SoulScanner\SearchByTime.xaml.cs 360 23 SoulScanner
d. Error 3 The best overloaded method match for 'SoulScanner.dgvRecords.dgvRecords(System.Linq.IQueryable)' has some invalid arguments C:\Users\KC\Desktop\SoulScanner\SoulScanner\SearchByTime.xaml.cs 363 28 SoulScanner