I am trying to run a query where I get the name of locations and the number of items in that location. So if i have a program that contains 3 locations I want to know how many programs are in that location..I need to use this with a lambda expression or linq to entities.
return Repository.Find(x => x.Location.Name.Count())...clearly missing something here.
we'll just assume I have a Program entity with ProgramID, ProgramName, LocationName...need to know how many programs are in at a location
You can do it like this:
return repository.Count(x => x.Location == "SomeLocation");
Do you want to know the counts for all locations at once?
var locCounts = Repository.GroupBy(prog => prog.Location.Name).ToLookup(g => g.key, g => g.Count());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With