如何将 IQueryable转换为 IQueryable到列表?
刚刚学习 LINQ,我在测试项目中遇到了新手障碍。你能解释一下我做错了什么吗?
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>;
}
我收到一条错误消息,内容如下:
无法将方法组“ToList”转换为非委托类型 'System.Collections.Generic.List' 你打算 调用方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要括号:
lists.ToList();
另外,您不必声明类型参数,即您可以使用以下内容并让类型系统推断类型参数:
lists.ToList();
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();
您只是缺少 ToList 上的右括号,应该是:
或
You are just missing the closing brackets on ToList, should be:
or