Let's say I have this structure:
class Ticket
{
int Id;
bool Void;
}
Is it possible to use LINQ to get an Anonymous Type with this two aggregated properties?
select new {totalVoid = numVoidTickets, totalNonVoid = numNonVoidTickets};
I thought this could be an approach:
from t in Tickets
select new { totalVoid = t.Id.Count(x => x.Void == true,
totalNonVoid = t.Id.Count(x => x.Void == false };
but intellisense is not showing Count() after I type t.Id nor t.
t is single item in your expression.
You don't need outer Select / 'from` to get this information:
var result = new
{
totalVoid = Tickets.Count(x => x.Void == true),
totalNonVoid = Tickets.Count(x => x.Void == false)
};
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