views:

50

answers:

3

I cannot use ToList<Tresult>() extension method. The code I use is,

 return this.Semesters.ToList<ISemester>()

'Semesters' in above code is an EntityCollection. These using directives are already present,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

Still I cannot Compile as it keeps on complainting that System.Data.Objects.DataClasses.EntityCollection<Semester> does not contain a definition for 'ToList' and the best extension method overload System.Linq.ParallelEnumerable.ToList<TSource>(System.Linq.ParallelQuery<TSource>) has some invalid arguments

+1  A: 

Lack of a reference to the System.Core assembly? That would probably do it...

EDIT: There has to be something in the System.Linq namespace, or that would have failed to compile. I thought that maybe PFX was making that bit work... but assuming you're using .NET 4, the ParallelEnumerable class is also in System.Core.

What happens if you type Enumerable. - does that show anything?

Jon Skeet
Absent that reference, you would think `using System.Linq;` would highlight as invalid, wouldn't it?
Anthony Pegram
@Anthony: I wondered whether ParallelEnumerable was in a different assembly, but it's not - at least not in .NET 4.
Jon Skeet
I have an existing reference to System.Core in my project references section.There is no such namespace, right?
Threecoins
@Threecoins: What do you mean by "there is no such namespace"? System.Core is an assembly, not a namespace - it's the assembly which contains System.Linq.Enumerable.
Jon Skeet
yes, i know, I already had reference to system.core assembly. I meant, since it was not a namespace I didn't mention it in the above question. Thanks for the support, problem was in my code as @Antony pointed out.
Threecoins
A: 

are you missing

System.Data
System.Data.DataSetExtensions
System.Data.Entity

in your references?

James Connell
If the compiler error mentions `EntityCollection<T>` then there's no using directive problems there...
Jon Skeet
Not in the using directives, I meant in the project references.
James Connell
+2  A: 

Are you sure Semester implements ISemester? As a test, I did this

interface ISemester { }
class Semester : ISemester { }

// ...

List<Semester> Semesters = new List<Semester>();
var query = Semesters.ToList<ISemester>();

Which is fine. However, change the class to simply be class Semester { }, and a syntactically-similar error to the one you reported surfaces.

Anthony Pegram
Oops! Yeah, my fault! Semester was implementing a different interface. But the error was misleading though.
Threecoins