无法隐式转换类型'System.Linq.IQueryable'到'System.Collections.Generic.IList“ [英] Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'

查看:2450
本文介绍了无法隐式转换类型'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'到'System.Collections.Generic.IList。一个显式转换存在(是否缺少强制转换?)

Error 1 Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆