我有一个C#-4 MVC3 RC测试应用程序,它使用实体框架4.EF4 LINQ的返回类型泛型列表
我有这样的方法:
public static List<Content> FetchMenu(int websiteID) {
return (from w in ContextHelper.Current.Websites
where w.WebsiteID == websiteID
select w.Contents).ToList();
}
这里涉及的对象(内容和网站)是EntityObject类型的。
上述函数给出编译错误:
Cannot implicitly convert type 'System.Linq.IQueryable<System.Collections.Generic.List<Manager.Models.Content>>' to 'System.Collections.Generic.List<Manager.Models.Content>'. An explicit conversion exists (are you missing a cast?)
w.Contents是EntityCollection<Content>
类型的集合。
如何推迟Linq.IQueryable类型以返回类型为Content的泛型列表?
我确实忘了括号,但它仍然给另一转换错误:为了完整起见,这里使用“查询综合”语法无法隐式转换类型“System.Collections.Generic.List>'改为'System.Collections.Generic.List ' –
peter
2010-11-20 23:00:47