You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Linq筛选数据库中Status为Inactive的记录?技术求助

实现加载Status为Inactive数据的Linq查询修改方案

你只需要在原Linq语句中添加Where筛选条件,过滤出Status列值为Inactive的记录即可,修改后的完整代码如下:

public IActionResult UrlDatasource([FromBody] DataManagerRequest dm)
{
    IEnumerable DataSource = _context.Customer
        .Where(x => x.Status == "Inactive") // 添加筛选条件
        .OrderByDescending(x => x.OrderNo)
        .ToList();
    DataOperations operation = new DataOperations();            
    return dm.RequiresCounts ? Json(new { result = DataSource}) : Json(DataSource);
}

关键修改说明

  • 通过Where(x => x.Status == "Inactive")指定筛选规则,只保留状态为Inactive的客户数据
  • 保持原有的OrderByDescending(x => x.OrderNo)降序排序逻辑(如果不需要排序可直接移除该方法)

原始数据

IdCustomerStatus
1MaryActive
2JaneActive
3VickyInactive
4AnnaActive

预期输出数据

IdCustomerStatus
3VickyInactive

内容的提问来源于stack exchange,提问作者Ken John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 16:43:13