【问题标题】:LINQ filter fields that starts with a particular integer以特定整数开头的 LINQ 筛选器字段
【发布时间】:2021-03-12 20:12:35
【问题描述】:

我需要过滤以特定integerintegers 列表开头的字段。例如,当我输入一个整数(ex: 1)时,查询应该返回1, 10, 119, 1187, 1098.

下面的query 给了我所有SchoolsId1。但是,我需要对其进行修改,使其返回 1, 10, 119, 1187, 1098.

return await _dbContext.Schools.Where(c => c.Id == Convert.ToInt32(schoolId)).Take(5).ToListAsync() ;

【问题讨论】:

  • Where(c => c.Id.ToString().StartsWith(schoolId))) ?

标签: c# entity-framework linq


【解决方案1】:

你可以这样做,假设:

  1. Id 是一个整数
  2. schoolId 是一个字符串
return await _dbContext
   .Schools
   .Where(c => c.Id.ToString().StartsWith(schoolId)).Take(5).ToListAsync();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    相关资源
    最近更新 更多