/// <summary>
        ///     Gets the data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="totalRecords">The total records.</param>
        /// <returns>List&lt;Row&gt;.</returns>
        /// <exception cref="Exception">
        ///     When paging is enabled,
        ///     QueryResult must contain the TotalRecords
        /// </exception>
        /// TODO Edit XML Comment Template for GetData
        internal override List <Row> GetData(
            GridContext context,
            out int?totalRecords)
        {
            var resultRows = new List <Row>();

            var queryResult = RetrieveData(context);

            totalRecords = queryResult.TotalRecords;

            if (context.GridDefinition.Paging &&
                !totalRecords.HasValue)
            {
                throw new Exception(
                          "When paging is enabled, QueryResult must contain the TotalRecords");
            }

            var templatingEngine =
                (IMvcGridTemplatingEngine)Activator.CreateInstance(
                    context.GridDefinition.TemplatingEngine,
                    true);

            foreach (var item in queryResult.Items)
            {
                var thisRow = new Row();

                var rowCss = RowCssClassExpression?.Invoke(item, context);

                if (!string.IsNullOrWhiteSpace(rowCss))
                {
                    thisRow.CalculatedCssClass = rowCss;
                }

                foreach (var col in Columns)
                {
                    var thisCell = new Cell();
                    thisRow.Cells.Add(col.ColumnName, thisCell);

                    thisCell.HtmlText = "";

                    if (col.ValueExpression != null)
                    {
                        thisCell.HtmlText = col.ValueExpression(item, context);
                    }

                    if (!string.IsNullOrWhiteSpace(col.ValueTemplate))
                    {
                        var templateModel = new TemplateModel
                        {
                            Item        = item,
                            GridContext = context,
                            GridColumn  = col,
                            Row         = thisRow,
                            Value       = thisCell.HtmlText
                        };

                        thisCell.HtmlText = templatingEngine.Process(
                            col.ValueTemplate,
                            templateModel);
                    }

                    if (col.HtmlEncode)
                    {
                        thisCell.HtmlText =
                            HttpUtility.HtmlEncode(thisCell.HtmlText);
                    }

                    thisCell.PlainText = thisCell.HtmlText;
                    if (col.PlainTextValueExpression != null)
                    {
                        thisCell.PlainText =
                            col.PlainTextValueExpression(item, context);
                    }

                    var cellCss =
                        col.CellCssClassExpression?.Invoke(item, context);

                    if (!string.IsNullOrWhiteSpace(cellCss))
                    {
                        thisCell.CalculatedCssClass = cellCss;
                    }
                }

                resultRows.Add(thisRow);
            }

            return(resultRows);
        }
 /// <summary>
 ///     Gets the data.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="totalRecords">The total records.</param>
 /// <returns>List&lt;Row&gt;.</returns>
 /// TODO Edit XML Comment Template for GetData
 internal abstract List <Row> GetData(
     GridContext context,
     out int?totalRecords);