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

3 posts, 0 answers
  1. Mitchell
    Mitchell avatar
    2 posts
    Member since:
    May 2012

    Posted 17 Mar 2013 Link to this post

    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.

  2. Mitchell
    Mitchell avatar
    2 posts
    Member since:
    May 2012

    Posted 19 Mar 2013 Link to this post

    The same thing seems to happen to DataTables as well.  This is a critical issue that I need resolved.
  3. Daniel
    Admin
    Daniel avatar
    2219 posts

    Posted 20 Mar 2013 Link to this post

    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!
Back to Top