【问题标题】:Exclude rows starting from certain characters using Linq使用 Linq 排除从某些字符开始的行
【发布时间】:2013-07-01 19:51:28
【问题描述】:

我有如下的 sql 查询,它排除了从字母 x 开始的行

select * from table where name like 'x%'

我如何使用 Linq 编写它?

我尝试过使用

 var query = (from a in _tableARepository.AsQueryable()
              join b in _tableBRepository.AsQueryable()
                   on a.Id equals b.Id
              where a.name.contains("x") 
              select new { a, b});

但这包括所有带有“x”的东西

【问题讨论】:

    标签: c# linq


    【解决方案1】:

    如果 a.name 是字符串,则使用where a.name.StartsWith("x")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      • 2019-11-15
      • 2015-10-28
      • 1970-01-01
      相关资源
      最近更新 更多