首页 > 解决方案 > Entity Core Distinct 在不同字段上作为 where 字段

问题描述

我需要对某个日期的所有记录进行选择,但在另一个字段上收到不同的记录。

这是我目前在尝试获得不同结果之前所拥有的。

var entity = _context.ClientOrder
            .Where(s => s.DateScanned == datetime)
            .OrderBy(s => s.Sequence)
            .Include(s => s.ClientVehicle)
            .ThenInclude(s => s.ClientDetails)
            .ToList();

我希望有这样的东西

var entity = _context.ClientOrder
            .Where(s => s.DateScanned == datetime)
            .Select(s => s.GroupId)
            .Distinct()
            .OrderBy(s => s.Sequence)
            .Include(s => s.ClientVehicle)
            .ThenInclude(s => s.ClientDetails)
            .ToList();

根据建议,我现在正在尝试使用 GroupBy() 但它似乎不起作用。我的语法错了吗?

var entity = _context.ClientOrder
            .GroupBy(s => s.GroupId)
            .Where(s => s.DateScanned == datetime)
            .OrderBy(s => s.Sequence)
            .Include(s => s.ClientVehicle)
            .ThenInclude(s => s.ClientDetails)
            .ToList();

标签: c#entity-framework-core

解决方案


推荐阅读