加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何使用List

发布时间:2020-12-16 01:58:48 所属栏目:百科 来源:网络整理
导读:我需要从我的数据库中获取billers列表. 这是我的代码: public static Listdynamic GetBillers(){ DataLayer.DLContext context = new DataLayer.DLContext(); var Billers = (from b in context.Biller where b.IsActive == true b.IsDeleted == false sele
我需要从我的数据库中获取billers列表.
这是我的代码:

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();

应该做的工作.但就个人而言,我不确定这是一个特别有用的举动 – 我建议返回一个已知的类/接口.动态有各种用途,但这不是一个好的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读