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

No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible

4 Answers 1419 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mitchell
Top achievements
Rank 1
Mitchell asked on 17 Mar 2013, 10:18 PM

I am having some issues with the MVC Wrappers for Kendo UI. It seems that IEnumerable does not support any aggregate values other than count. The exception that I get is: No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.  I am using System.LInq.Dynamic but this issue occurs without using a Dynamic query.

I am not sure how to get around this issues nor am I sure if it is a flaw with Kendo.
Controller

public ActionResult Index() { return View(); }
public ActionResult Read([DataSourceRequest] DataSourceRequest request) { return GetView(request); }
private IEnumerable<dynamic> GetData() { var db = new NwEntities(); return db.Products.Select("new(ProductID,ProductName,UnitPrice)"); }
private JsonResult GetView(DataSourceRequest request) { return Json(GetData().ToDataSourceResult(request)); }

View

@model IEnumerable<dynamic>
@(
 Html.Kendo().Grid(Model).Name("Grid")
    .DataSource(ds =>
        ds.Ajax()
        .Model(m =>
        {
            m.Id("ProductID");
            m.Field("ProductName", typeof(string));
            m.Field("UnitPrice", typeof(decimal));
        })
        .Aggregates(aggregate => aggregate.Add(a => "UnitPrice").Count().Sum())
        .Read(r => r.Action("Read", "Home"))
    )
    .Columns(columns =>
    {
        columns.Bound("ProductID");
        columns.Bound("ProductName");
        columns.Bound("UnitPrice").Format("{0:c}");
    })
    .Groupable()
)

I have spent a week trying to get this to work with no luck and this is a critical issue.

4 Answers, 1 is accepted

Sort by
0
Mitchell
Top achievements
Rank 1
answered on 19 Mar 2013, 06:20 PM
The same thing seems to happen to DataTables as well.  This is a critical issue that I need resolved.
0
Daniel
Telerik team
answered on 20 Mar 2013, 08:11 AM
Hello Mitchell,

You should use the overload that accepts the member name and member type when binding to dynamic objects e.g.

Aggregates(agg => agg.Add("UnitPrice", typeof(decimal)).Sum().Count())
Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Priyank
Top achievements
Rank 1
Veteran
answered on 31 Mar 2021, 05:34 PM

Hello Admin,

I am getting error when i applied sum() aggregates with group by.

I am using kendo ui for MVC. I am binding the grid using ServerOperation(true). We have some group by functionality with aggregates function in dynamic way. So we have create jquery function and add group by and aggregates with jquery.

The group by is applied on grid but aggregates sum() function is not applied on grid and throw below error

"System.InvalidOperationException: No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic".

I attached image of jquery code and grid code.

Update me on this.

 

Thanks.

0
Tsvetomir
Telerik team
answered on 02 Apr 2021, 09:39 AM

Hi Priyank,

Based on the provided information, I suspect that the data type for the field is not a primitive data type. Is that correct?

The Kendo UI DataSource internally uses the Sum() LINQ query that applies the aggregate only to primitive data types. Hence, if you have a complex object such as an IEnumerable, you should handle the aggregation on your own. A similar approach where the custom aggregation is shown can be found in the live demo below:

https://demos.telerik.com/aspnet-mvc/grid/customajaxbinding

I hope you find this helpful.

 

Regards,
Tsvetomir
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Mitchell
Top achievements
Rank 1
Answers by
Mitchell
Top achievements
Rank 1
Daniel
Telerik team
Priyank
Top achievements
Rank 1
Veteran
Tsvetomir
Telerik team
Share this question
or