0

Error:

Cannot convert method group 'ToList' to non-delegate type 'System.Collections.Generic.List'. Did you intend to invoke the method? D:\PROJECTS\CECB2013-03-26\CECB\cecb.Functions\ActivationCodeEmail.cs 102 20 cecb.Functions*

My code is

 List<Members> teamMembers = new List<Members>();

 var query = from c in cecbContext.Projects
             join b in cecbContext.TeamMembers on c.proj_team equals b.team_reference
             join d in cecbContext.Members on b.mem_reference equals d.mem_reference
             select new
                    {
                        d.mem_reference
                    };

    return query.ToList<Members>;
}

1 Answer 1

1

You've forgotten the brackets after ToList - it's an ( extension ) method:

return query.ToList<Members>();

You have another problem, though - you trying to turn an IQueryable<AnonymousType> into a List<Members>.

If you create instances of Members in your Select clause, it will work and you will be able to omit the generic type parameter on ToList()

select new Members
{
  ...
};

return query.ToList(); // this will create a List<Members>
Sign up to request clarification or add additional context in comments.

4 Comments

no buddy then it say's Error 6 'System.Linq.IQueryable<AnonymousType#1>' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments
@Gayashan oh - you have to add using System.Linq; too as IQueryable<T>.ToList() is an extension method.
Error 5 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<cecbData.Members>' again im getting this error
@Gayashan That's because you're selecting an anonymous type with select new { ... }. See the second part of my answer. You could start a new question as this is a different problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.