aspnetcore
aspnetcore copied to clipboard
LINQ Select returns wrong count of a ICollection<T>
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();

