gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 04:13:44 25 4
gpt4 key购买 nike

我有一个方法:

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;
}

选择的地方有错误:

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?)

知道如何解决我的问题吗?

最佳答案

要将 IQuerableIEnumerable 转换为列表,您可以执行以下操作之一:

IQueryable<object> q = ...;
List<object> l = q.ToList();

或:

IQueryable<object> q = ...;
List<object> l = new List<object>(q);

关于c# - 无法将类型 'System.Linq.IQueryable' 隐式转换为 'System.Collections.Generic.IList',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3402822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com