gpt4 book ai didi

c# - 如何使用列表<动态>

转载 作者:行者123 更新时间:2023-11-30 14:11:22 25 4
gpt4 key购买 nike

我需要从我的数据库中获取账单列表。这是我的代码:

public static List<dynamic> GetBillers()
{
DataLayer.DLContext context = new DataLayer.DLContext();

var Billers = (from b in context.Biller
where b.IsActive == true && b.IsDeleted == false
select new
{
ID = b.ID,
DisplayName = b.DisplayName
}).ToList();

return Billers;
}

我收到这个错误:

Cannot implicitly convert type Collections.Generic.List<AnonymousType#1> to System.Collections.Generic.List<dynamic>

请帮忙。

最佳答案

(from b in context.Biller
where b.IsActive == true && b.IsDeleted == false
select (dynamic) new {
ID = b.ID,
DisplayName = b.DisplayName
}).ToList();

应该做的工作。不过,就我个人而言,我不确定这是一个特别有用的举措——我建议改为返回一个已知的类/接口(interface)。 dynamic 有多种用途,但这不是一个好用途。

关于c# - 如何使用列表<动态>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20371014/

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