Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linq Distinct Troubles

Posted on 2010-11-19
2
Medium Priority
?
542 Views
Last Modified: 2013-11-11
I am tiring to select distinct values by a object property.  What am I doing wrong?  I am getting the errors:


Error      14      'System.Linq.IOrderedEnumerable<MB.Core.Record>' does not contain a definition for 'Distinct' and the best extension method overload 'System.Linq.ParallelEnumerable.Distinct<TSource>(System.Linq.ParallelQuery<TSource>, System.Collections.Generic.IEqualityComparer<TSource>)' has some invalid arguments      

and

Error      15      Instance argument: cannot convert from 'System.Linq.IOrderedEnumerable<MB.Core.Record>' to 'System.Linq.ParallelQuery<MB.Core.RecordLesson>'

Code Posted Below.

Thanks!

List<Record> allStudentRecords = RecordBuilder.GetAllRecordsByStudentId(CurrentStudent.StudentId).OrderByDescending(r => r.RecordLevel).Distinct(new DistinctLesson()).ToList<Record>();


    public class DistinctLesson : IEqualityComparer<RecordLesson>
    {
        public bool Equals(RecordLesson x, RecordLesson y)
        {
            return x.RecordLessonName.Equals(y.RecordLessonName);
        }

        public int GetHashCode(RecordLesson obj)
        {
            return obj.RecordLessonName.GetHashCode();
        }
    }

Open in new window

0
Comment
Question by:grogo212
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 2000 total points
ID: 34176866
What type does RecordBuilder.GetAllRecordsByStudentId return?

It appears from the code that it returns a Record object, but you're trying to pass it to an equality comparer that expects a RecordLesson object.
0
 

Author Comment

by:grogo212
ID: 34176896
Your Right! Silly mistake

Here's my modified code:
public class DistinctLesson : IEqualityComparer<Record>
    {
        public bool Equals(Record x, Record y)
        {
            return x.RecordLesson.RecordLessonName.Equals(y.RecordLesson.RecordLessonName);
        }

        public int GetHashCode(Record obj)
        {
            return obj.RecordLesson.RecordLessonName.GetHashCode();
        }
    }

Open in new window

0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question