Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to perform Linq`s group by and sum operation on List<Dictionary<string, object>>
    primarykey
    data
    text
    <p>I have the following code. For every item in <code>objViewForecastTrendYear2</code>, I'm creating creating <code>DicGridRow</code> dictionary object. I add some properties dynamically along with some static properties in <code>DicGridRow</code> dictionary. At the end I am adding that item in <code>List</code> of <code>Dictionary EntireViewModel</code>. Once I come out of outer loop ,i have <code>List&lt;Dictionary&gt; EntireViewModel</code>.</p> <p>This list contains some record and i want to apply group by and sum using linq on this <code>EntireViewModel</code>, but I don't know how to do that. Here <code>objViewForecastTrendYear2</code> is list object which contain all static properties.</p> <p>Overall scenario is <code>EntireViewModel =( A(static properties)+B(Dynamic properties))</code> for every item in <code>objViewForecastTrendYear2</code>.</p> <p>I want to apply group by on all ID field like UOM_ID and remaining fields in sum operation of Linq on <code>EntireViewModel</code>. My EntireViewModel look like -> <img src="https://i.stack.imgur.com/FGMXc.png" alt="enter image description here"></p> <pre><code>List&lt;Dictionary&lt;string, object&gt;&gt; EntireViewModel = new List&lt;Dictionary&lt;string, object&gt;&gt;(); foreach (var A in objViewForecastTrendYear2) { DynamicColName = new string[NoOfHistoryColumn]; int HistoryCol = RightHistoryColumn; Dictionary&lt;string, object&gt; DicGridRow = new Dictionary&lt;string, object&gt;(); DicGridRow.Add("COMPANY_ID", A.COMPANY_ID); DicGridRow.Add("CUSTOMER_ID", A.CUSTOMER_ID); DicGridRow.Add("FINAL_FORECAST", A.FINAL_FORECAST); DicGridRow.Add("FINANCIAL_YEAR", A.FINANCIAL_YEAR); DicGridRow.Add("FORECAST_MONTH", A.FORECAST_MONTH); DicGridRow.Add("FORECAST_PARAMETERS_ID", A.FORECAST_PARAMETERS_ID); DicGridRow.Add("MARKET_PLANNER", A.MARKET_PLANNER); DicGridRow.Add("PROD_GRADE_ID", A.PROD_GRADE_ID); DicGridRow.Add("PROD_ID", A.PROD_ID); // DicGridRow.Add("SALES_LAST_YEAR", A.SALES_LAST_YEAR); DicGridRow.Add("STATISTICAL_FORECAST", A.STATISTICAL_FORECAST); DicGridRow.Add("STOCK_POINT_ID", A.STOCK_POINT_ID); DicGridRow.Add("TREND_ID", A.TREND_ID); DicGridRow.Add("UOM_ID", A.UOM_ID); DicGridRow.Add("VERSION_NO", A.VERSION_NO); DicGridRow.Add("CUSTOMER_FORECAST",A.CUSTOMER_FORECAST); // Dynamic columns goes as follows for (int i = 0; i &lt; NoOfHistoryColumn; i++) { string strColumnName = Convert.ToString(HistoryCol--); DynamicColName[i] = strColumnName; //Dictionary&lt;string, object&gt; DicGridRow = new Dictionary&lt;string, object&gt;(); DicGridRow.Add(strColumnName, A.SALES_LAST_YEAR); } EntireViewModel.Add(DicGridRow); } </code></pre> <p><em>As you can see my <code>List</code> is of <code>dictionary&lt;string, object&gt;</code> object Now the grouping of List has to be done based upon 2 or more keys of dictionary as we do in SQL databases (ex. PL-SQL).</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload