c# - Use Linq to SQL to generate sales report -


In order to generate a sales report from the last 30 days, I currently have the following code, I would like to know whether to leak this report It is possible to generate this report even in one step rather than one original step.

For my requirement, one need to return a price for every day. If I do not have any sales for any day, then 0 is returned.

In any of the examples of Limca, it is not understood how far it is possible to include the filter.

Thank you for your help, Rich

 < Date> date set date of using code> // setup date time date = date time.NEW ADDES (-29); Date Timeout Date = Date Time.Now Add days (1); Start time session = new timepan (0, 0, 0); Timespain andts = new timespan (23, 59, 59); (Selling Sales Forced = D.C.Orders for today's sale to midnight from 29 days ago using {var dc = new DataContext ()). Where (b = & gt; b order datetime & gt; convert.datetime (startup) .date + start) & amp; Amp; B Order date time & lt; = Convert. ToDateTime (endDate.Date + endTS)); // Submit loops and total orders through each day, if no one is set to 0 (startDate! = EndDate) {decimal totalSales = 0m; Date Time Startup = startDate.Date + startTS; Date expiration date = startDate.Date + endTS; Foreign sales (sales sales in sales) Where (b = & gt; b order datetime & gt; rad & amp; order order datetime & lt; = & day)) {totalals + = (decimal) sales. OrderPrice; Response.Write ("From Date:" + Initial + "- To Date:" + Finally + ". Sales:" + string.format ("{0: 0.00}", total cell) + "& lt; Br> "); // Start the next day Start = Start. Add Date (1); }}  

EDIT: Johannes North was a great way to manage my query. Below is an adjustment of code to work for this example, if someone has this problem. It will display an external insertion from the AllDays table and will return 0 values ​​if there is no sale for that day.

  var query = from d All in allays, when joining the sale, select b. S from J.DefaultIfEmpty (s) in the directory B. equals s.day J New {days = D, Kulals = ( S! = Null)? S.totalSales: 0m};  

You can group all your data by day and run yoga on those groups Are there. To meet the requirement of having a zodiac sign for every day, even without those orders, you can either join the list of all dates or to ensure that only all dates are included. , Just use a loop. Small Hints: If you compare the DateTime.Date properties, you do not need to explicitly set the time.

Here's a solution using a generator function (Project taken from MoreLinq):

  Public static partial orbit greater American {public static IEnumerable & lt; TResult & gt; GeneratedxX < TResult & gt; (Func & lt; int, TResult & gt; generator) {// looping over 0 ... int.MaxValue is a pain inclusive. Exclusive to go simple, // then go for int.MaxValue again. For (int i = 0; i  

Comments