aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

LINQ Select returns wrong count of a ICollection<T>

Open cschuchardt88 opened this issue 3 years ago • 0 comments

var something = _db.somethingtable // database table with 2 records, One with having , 1 URI
// record in the list and other having,  4 records in the list. but 3 have a status of delete
                .Include(i => i.Uris.Where(w => w.Status != Status.Delete)).ThenInclude(t => t.Requests)
                .Include(i => i.Uris.Where(w => w.Status != Status.Delete)).ThenInclude(t => t.Domain)
                .Where(w => w.Id == userId && w.Status != GroupStatus.Delete);
//something has two records both with URIs list; count is 1

model.Uris = await something.Select(s => new UriViewModel()
            {
                UriId = s.Id,
                UriName = s.Name,
                TotalUris = s.Uris.Count, // returns 4. even tho the list doesnt doesnt have 4; says 1
            }).ToArrayAsync();

image

image

cschuchardt88 avatar Oct 15 '22 08:10 cschuchardt88