Anthony DeFreitas
Anthony DeFreitas

Reputation: 3

LINQ get the count

I have the following query which is returning the expected result but I'm having trouble accessing the Tickets count:

home.Projects = _db.Projects.Where(p => p.Users.Any(u => u.Id == userid)).Include(t => t.Tickets).ToList();

Upvotes: 0

Views: 49

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

Use SelectMany:

home.Projects.SelectMany(i => i.Tickets).Count();

SelectMany compresses the one to many result into a singular result for this very purpose.

Upvotes: 2

Related Questions