Get Distinct Entries Based On Specific Column in Entity Framework

后端 未结 3 1258
暖寄归人
暖寄归人 2021-01-28 10:55

I have a SQLite table that contains every test result we\'ve run, and I\'m looking to write an entity framework query that returns only the most recent test result per project.

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-28 11:34

    Try with a subquery instead of a grouping. Like this:

    results = await _context.Results
                .Include(x => x.Project)
                .AsNoTracking() 
                .Where( r => r.Id == _context.Results.Where( rr => rr.ProjectId == r.ProjectID).Max( rr => rr.Id) )
                .ToListAsync();
    

提交回复
热议问题