views:

1544

answers:

2

Hi guys,

Just learning LINQ and i've come to a newbie roadblock in my test project. Can you explain what i'm doing wrong?

 public List<ToDoListInfo> retrieveLists(int UserID)
    {
        //Integrate userid specification later - need to add listUser table first
        IQueryable<ToDoListInfo> lists = from l in db.ToDoLists
                                         select new ToDoListInfo { ListID = l.ListID, ListName = l.ListName, Order = l.Order, Completed = l.Completed };

        return lists.ToList<ToDoListInfo>;
    }

I'm getting an error saying the following:

Cannont convert method group 'ToList' to non-delegate type 'System.Collections.Generic.List' Do you intend to invoke the method?

+9  A: 

You just need parantheses:

lists.ToList<ToDoListInfo>();

Also, you do not have to declare the type parameter, i.e. you could use the following and let the type-system infer the type parameter:

lists.ToList();

Thomas Danecker
+2  A: 

You are just missing the closing brackets on ToList, should be:

 ToList();

or

ToList<ToDoListInfo>();
Nathan W