不能将类型“System.Linq.IQueryable”隐式转换为“System.Collections.Generic.IList” [英] Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'
本文介绍了不能将类型“System.Linq.IQueryable”隐式转换为“System.Collections.Generic.IList”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个方法:
public DzieckoAndOpiekunCollection GetChildAndOpiekunByFirstnameLastname(string firstname, string lastname)
{
DataTransfer.ChargeInSchoolEntities db = new DataTransfer.ChargeInSchoolEntities();
DzieckoAndOpiekunCollection result = new DzieckoAndOpiekunCollection();
if (firstname == null && lastname != null)
{
IList<DzieckoAndOpiekun> resultV = from p in db.Dziecko
where lastname == p.Nazwisko
**select** new DzieckoAndOpiekun(
p.Imie,
p.Nazwisko,
p.Opiekun.Imie,
p.Opiekun.Nazwisko)
;
result.AddRange(resultV);
}
return result;
}
并在所选地点出现错误:
and error in selected place :
错误1不能将类型'System.Linq.IQueryable< WcfService1.DzieckoAndOpiekun>。'隐式转换为'System.Collections.Generic.IList< WcfService1.DzieckoAndOpiekun>'。存在一个明确的转换(你错过了一个演员?)
Error 1 Cannot implicitly convert type 'System.Linq.IQueryable<WcfService1.DzieckoAndOpiekun>' to 'System.Collections.Generic.IList<WcfService1.DzieckoAndOpiekun>'. An explicit conversion exists (are you missing a cast?)
任何想法如何解决我的问题?
Any idea how solve my problem?
推荐答案
将 IQuerable
或 IEnumerable
转换为列表,您可以执行以下操作之一:
To convert IQuerable
or IEnumerable
to a list, you can do one of the following:
IQueryable<object> q = ...;
List<object> l = q.ToList();
或:
IQueryable<object> q = ...;
List<object> l = new List<object>(q);
这篇关于不能将类型“System.Linq.IQueryable”隐式转换为“System.Collections.Generic.IList”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文