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

使用LINQ统计指定日期下EventID唯一的记录数

Solution to Count Distinct EventIDs by Date

Got it, let's tweak your existing LINQ query to count unique EventIDs for the specified date instead of just all matching records. Here's the adjusted code:

@Model.DateAndTimes
    .Where(f => f.DateAndTimeDateType.Value.DayOfYear == renderedDayWithTime.DayOfYear)
    .Select(f => f.EventID)
    .Distinct()
    .Count()

How this works:

  • The Where clause stays exactly as your original code, filtering records to only those matching the target date's day of year.
  • Select(f => f.EventID) pulls out just the EventID values from the filtered records—we don't need the rest of the data for counting unique IDs.
  • Distinct() removes duplicate EventID entries, so even if multiple records share the same EventID on the same date, it only keeps one instance.
  • Finally, Count() gives you the total number of unique EventIDs for that date, which matches your example scenario (where 5 records with the same EventID would count as 1).

内容的提问来源于stack exchange,提问作者Mischa Morf

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:24:41