无法隐式将类型'System.Linq.IQueryable'转换为'System.Collections.Generic.IList'。

24 浏览
0 Comments

无法隐式将类型'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)
    {
        var 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.ToList());
    }
    return result;
}

在选择的位置出现错误:

错误 1 无法隐式将类型“System.Linq.IQueryable”转换为“System.Collections.Generic.IList”。存在一个显式转换(是否缺少强制转换?)

有任何解决方法吗?

0