我有一个方法:无法隐式转换类型 '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;
}
和错误在选定的地方:
错误1不能隐式地将类型'System.Linq.IQueryable <WcfService1.DzieckoAndOpiekun>'转换为'System.Collections.Generic.IList <WcfService1.DzieckoAndOpiekun>'。存在明确的转换(您是否缺少演员?)
任何想法如何解决我的问题?
理想的解决方案,Tnx! :) – netmajor 2010-08-04 06:04:00
当然'.ToArray()'Linq扩展也可以用在这种情况下(因为'T []'也是'IList')。但是'AddRange'方法实际需要什么?也许他可以使用'var'(这意味着'IQueryable '),'AddRange'会对此感到满意吗?注意:'IQueryable <>'继承'IEnumerable <>'。 –
2016-08-29 10:27:24