I Could Not Solve the Emptyprojectionmember Error in Ef Core

I have a table on access. The structure of this table is as follows. In this table, I record access information of 2 types of people. The GC field indicates whether the access is entry or exit. I am trying to get the number of people whose last movement is inside according to the type of person.

But I get an error:

The given key 'EmptyProjectionMember' was not present in the dictionary

I kindly ask for your support on the subject.

AccessData model:

public required string DeviceName { get; set; }
public required string CardNumber { get; set; }
public required string CardName { get; set; }
public required string PersonName { get; set; }
public string? PersonMiddleName { get; set; }
public required string PersonLastName { get; set; }
public DateTime? AccessTime { get; set; }
public int? GC { get; set; }
public int? AccessType { get; set; }
public string? Info { get; set; }
public required string PersonId { get; set; }

Query:

var totalInsideVisitors = await _context.AccessDatas
     .Where(a => a.AccessType == 2)
     .GroupBy(a => new { a.PersonId, a.AccessType })
     .Select(g => g.OrderByDescending(a => a.AccessTime).FirstOrDefault())
     .Where(a => a != null)
     .CountAsync(a => a.GC == 1);
7
Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article