This is a migrated thread and some comments may be shown as answers.

[Solved] Aggregates and OpenAccess

2 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lars Solberg
Top achievements
Rank 1
Lars Solberg asked on 12 May 2011, 10:50 PM
I have a simple grid set up to server bind to a collection of OpenAccess Entities:

Controller:
public ActionResult Index()
       {
           var SmContext = new SmDataEntities.EntitiesModel();
           return View(SmContext.Smdetails);
       }

View:
@model IEnumerable<SmDataEntities.Smdetail>
@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>{
        columns.Bound(o => o.Amt)
        .Aggregate(aggregates => aggregates.Count())
        .FooterTemplate(@<text>Total Count: @item.Count</text>)
        .GroupFooterTemplate(@<text>Count: @item.Count</text>);
        })
.Sortable()
.Pageable()
.Groupable())

Without the aggregate added to the column, the grid works perfectly. With the aggregate it produces this error:
[NotSupportedException: Execution of 'System.Linq.Queryable:Where(IQueryable`1,Expression`1)' on the database server side currently not implemented.]
   Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single) +611
   Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single) +50
  
[NotSupportedException: An exception occured during the execution of '
Extent<SmDataEntities.Smdetail>.GroupBy(item => 1).OrderBy(group53499056 => group53499056.Key).Select(group53499056 => new AggregateFunctionsGroup() {Key = Convert(group53499056.Key), ItemCount = group53499056.Count(), HasSubgroups = False, AggregateFunctionsProjection = new DynamicClass1() {Count_Amt_63942930 = Extent<SmDataEntities.Smdetail>.Where(item => (1 == group53499056.Key)).Count()}, Items = group53499056})'. See InnerException for more details.
]
   Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single) +195
   Telerik.OpenAccess.Query.ExpressionExecution.PerformDatabaseQuery(Piece`1 piece, Object[] grpVals) +400
   Telerik.OpenAccess.Query.Piece`1.System.Collections.IEnumerable.GetEnumerator() +37
   Telerik.Web.Mvc.Extensions.QueryableExtensions.Aggregate(IQueryable source, IEnumerable`1 aggregateFunctions) +197
   Telerik.Web.Mvc.UI.GridDataProcessor.CalculateAggregates() +152
   Telerik.Web.Mvc.UI.Grid`1.CreateRenderingData() +1339
   Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +584
   Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString() +86
   Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString() +22
   Telerik.Web.Mvc.{Dynamic}.GridBuilder`1[[SmDataEntities.Smdetail, SmDataEntities, Version=1.0.0.0\, Culture=neutral\, PublicKeyToken=null\]\].IHtmlString.ToHtmlString() +5
   System.Web.HttpUtility.HtmlEncode(Object value) +38
   System.Web.WebPages.WebPageBase.Write(Object value) +64
   ASP._Page_Views_Aggregate_Index_cshtml.Execute() in c:\Work\Solberg\SmQueryMVC\SmQueryMVC\Views\Aggregate\Index.cshtml:7
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
   System.Web.WebPages.StartPage.RunPage() +19
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +65
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +220
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   Glimpse.Net.Plumbing.GlimpseView.Render(ViewContext viewContext, TextWriter writer) +30
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303
   Castle.Proxies.ControllerActionInvokerProxy.InvokeActionResult_callback(ControllerContext controllerContext, ActionResult actionResult) +13
   Castle.Proxies.Invocations.ControllerActionInvoker_InvokeActionResult.InvokeMethodOnTarget() +121
   Castle.DynamicProxy.AbstractInvocation.Proceed() +134
   Glimpse.Net.Interceptor.InvokeActionResultInterceptor.Intercept(IInvocation invocation) +335
   Castle.DynamicProxy.AbstractInvocation.Proceed() +534
   Castle.Proxies.ControllerActionInvokerProxy.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +126
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8892525
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184



If I force the controller to return the collection as a list, SmContext.Smdetails.ToList(), everything
works fine. This approach, however, has major performance implications. Is there anyway to do aggregates
without eager loading collections from OpenAccess?




This brings me to my next question. I have another grid that I am loading an OA entity as an IEnumerable,
but because of a relationship, it's causing a circular reference error. I've read the blogs and forums
about ways to get around this error, but I need the relationship defined and I take the performance hit if
I load into a custom viewmodel. I've even tried to alter the T4 templates to generate the [ScriptIgnore]
attribute for the property, but it didn't work. Is there anyway you can think of to have the js serializer
ignore this property?





Thanks in advance, and great job on the controls so far!

2 Answers, 1 is accepted

Sort by
0
Lars Solberg
Top achievements
Rank 1
answered on 20 May 2011, 05:06 PM
Any thoughts?  I'm trying to decide if these are the right products to use.

Thanks again
0
Damyan Bogoev
Telerik team
answered on 25 May 2011, 05:33 PM
Hello Lars Solberg,

1.    It seems that the generated Linq aggregate query cannot be executed on the server.
2.    Please have a look into the following code library where an approach of using proxies with WCF services is being used. The persistent capable objects cannot be serialized with JSON or XML. This code library example demonstrates how to use proxies for data-binding instead of persistent instances;

Greetings,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Lars Solberg
Top achievements
Rank 1
Answers by
Lars Solberg
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Share this question
or