I have a LINQ-to-SQL query that runs through a table, that I want to select 3 sum’s – the sums of ‘Rate’ and ‘AdditionalCharges’, so I have something like this:
var sums = from d in dc.Deliveries
where d.TripDate == DateTime.Now
select new
{
Rate = d.Rate,
AdditionalCharges = d.AdditionalCharges
};
However, obviously this returns a new row for every delivery, which means I have to sum them up afterwards – which seems fairly inefficient. Is there an easier way?
If you use query syntax you can do something like the following
this is off the top of my head and not tested