-
-
Notifications
You must be signed in to change notification settings - Fork 240
Closed
Labels
Description
This is my code:
var rows = extractedRows.AsQueryable();
var detailed = rows
.GroupBy("new (Region, Product)")
.Select("new (Key.Region as Region, Key.Product as Product, Sum(Convert.ToInt32(Sales)) as TotalSales, 0 as GroupLevel)");
// GROUPING SET 2: (Region)
var regionSubtotal = rows
.GroupBy("Region")
.Select("new (Key as Region, null as Product, Sum(Convert.ToInt32(Sales)) as TotalSales, 1 as GroupLevel)");How could I use Concat for detailed and regionSubtotal and order by Product the result using DynamicLINQ?
This code does not work:
var combined = detailed.Concat(regionSubtotal).AsQueryable();This code works but I could not use .OrderBy("Product").
var combined = detailed.ToDynamicList().Concat(detailed1.ToDynamicList()).AsQueryable();I need to calculate sorting expression using some metadata, so be able to have a string for sorting is a great help.
But I actually need to do in a code something like that:
CREATE TABLE SalesAlex (
Region VARCHAR(20),
Product VARCHAR(20),
Sales INT
);
INSERT INTO SalesAlex (Region, Product, Sales) VALUES
('North', 'Apples', 100),
('North', 'Oranges', 150),
('South', 'Apples', 200),
('South', 'Oranges', 250);
SELECT
Region,
Product,
SUM(Sales) AS TotalSales,
GROUPING_ID(Region, Product) AS GroupLevel
FROM SalesAlex
GROUP BY GROUPING SETS (
(Region, Product), -- Detailed totals
(Region), -- Subtotals by Region
() -- Grand total
)I made that working with Dynamic LINQ, but also need to sort the result by Product for example.
Any ideas really help!