locked
Group by in Lightswitch RRS feed

  • Question

  • Hi, i need some help with a group by in lightswitch, im doing this:

    But i need to group all the data by "Nombre" and grouping the months too, exists a way to do it?, thank you for your time and help.

    Wednesday, June 25, 2014 3:13 PM

Answers

  • You can use LINQ to do the grouping in LS. Look up: Enumerable.GroupBy. The syntax might take a while to get right, but it can do the same things as grouping in SQL.

    Here's an example:

    List<Lease> leases = building.LeasesReadyForNewInvoice;
    
    var leaseDates = leases.GroupBy(
       l => l.NextInvoiceToCreateDueDate,
       (nextInvoiceDueDate, dueDateLeases) => new { InvoiceDueDate = nextInvoiceDueDate, InvoiceCount = dueDateLeases.Count() }
    );
    
    confirmationMessage = "Are you sure you want to create these invoices?" + Environment.NewLine;
    
    leaseDates.ForEach(id => confirmationMessage += string.Format("{0:d}: {1}\n", id.InvoiceDueDate, id.InvoiceCount));
    

    Paul

    • Proposed as answer by Angie Xu Monday, July 7, 2014 1:56 AM
    • Marked as answer by Angie Xu Tuesday, July 8, 2014 5:58 AM
    Wednesday, July 2, 2014 7:37 PM

All replies

  • You can create a view in SQL Server to do the group by and then attach to the view.

    Then, you may want to create a query based on the view to add parameters and an order by and then finally add the query to your screen.

    Wednesday, July 2, 2014 5:39 AM
  • These VS gallery samples contain examples that may be of use:

    Manipulate sort and column settings programmatically

    LightSwitch control colors of DataGrid rows and other UI elements

    "The grid is styled in this screen using the DataGrid property AlternatingRowBackground to, as the name suggests, give alternate rows a different color. The grid is also styled with custom column sorting and grouping using the DataGrid PagedCollectionView technique, ..."

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Wednesday, July 2, 2014 8:58 AM
  • You can use LINQ to do the grouping in LS. Look up: Enumerable.GroupBy. The syntax might take a while to get right, but it can do the same things as grouping in SQL.

    Here's an example:

    List<Lease> leases = building.LeasesReadyForNewInvoice;
    
    var leaseDates = leases.GroupBy(
       l => l.NextInvoiceToCreateDueDate,
       (nextInvoiceDueDate, dueDateLeases) => new { InvoiceDueDate = nextInvoiceDueDate, InvoiceCount = dueDateLeases.Count() }
    );
    
    confirmationMessage = "Are you sure you want to create these invoices?" + Environment.NewLine;
    
    leaseDates.ForEach(id => confirmationMessage += string.Format("{0:d}: {1}\n", id.InvoiceDueDate, id.InvoiceCount));
    

    Paul

    • Proposed as answer by Angie Xu Monday, July 7, 2014 1:56 AM
    • Marked as answer by Angie Xu Tuesday, July 8, 2014 5:58 AM
    Wednesday, July 2, 2014 7:37 PM
  • Thanks for the comments and help, im gonna check that right now.
    Wednesday, July 2, 2014 7:48 PM