I have a query that select some value. The code is:
var query = from c in snd.external_invoices.OrderByDescending(x => x.date)
join o in snd.invoices on c.idexternal_invoices equals o.id_external_invoice
DateTime endOfMonth = new DateTime(c.date.Year,
c.date = endOfMonth;
DateTime nextMonth = c.date.AddMonths(1);
DateTime endOfNextMonth = new DateTime(c.date.Year,
c.date = endOfNextMonth;
I'm not sure you can pass in a complex calculation like ou want easily into a linq expression? Someone can fix me if I'm wrong with this.
What I would do probably, since your calculation depends only on your
tipologiaPagamento value only, and uses the
date value only in the calculation, which you have in your current result set anyway, not to bother myself doing that on the SQL side. Simply get all the needed information, and put your switch statement into a
foreach loop to update the values at the application server level as needed. Probably that'll be able to do the calculation faster than the SQL server, which is not necessarily optimized for data manipulation, but more for data retrieval.