group a field generates error fw core

2 posts, 1 answers
  1. Dario
    Dario avatar
    40 posts
    Member since:
    Jun 2018

    Posted 13 May 2020 Link to this post

    I have this tag

    @(Html.Kendo().Grid<Portale.Web2.Data.Entities.Contact>()
              .Name("contactGrid")
          .DataSource(dataSource => dataSource
              .Ajax()
              .Read(read => read.Action("GetContacts", "Contacts").Data("addInfo"))
           )
          .Columns(columns =>
          {
              columns.Bound(product => product.Date).Format("{0:dd/MM/yyyy}");
              columns.Bound(product => product.Name);
              columns.Bound(product => product.City);
              columns.Bound(product => product.SouceType);
              columns.Bound(product => product.Type);
              columns.Bound(product => product.Status);
              columns.Command(command => command.Custom("Completa").Visible("isNew").Click("completeContact"));
          })
          .Pageable(p =>
          {
              p.PageSizes(new[] { 5, 10, 30 });
              p.Info(true);
              p.Enabled(true);
          })
          .Sortable()
          .Groupable()
          .Filterable()
     
    )
    <script>
        function addInfo(e) {
            var statusFilter = $("#statusFilter").val();
         }
    </script>

     

    I call this action

     

    public ActionResult GetContacts([DataSourceRequest]DataSourceRequest request, string status = "")
            {
                if (status != "")
                {
                    var contacts = from rec in _context.Contacts
                                   where rec.Status == status.ToContactStatus()
                                   select rec;
                    DataSourceResult result = contacts.ToDataSourceResult(request);
                    return Json(result);
                }
                else
                {
                    var contacts = from rec in _context.Contacts
                                   select rec;
                    DataSourceResult result = contacts.ToDataSourceResult(request);
                    return Json(result);

     

    If I try to set a group, it shows me this exception

    System.InvalidOperationException
      HResult=0x80131509
      Messaggio=Processing of the LINQ expression '(GroupByShaperExpression:
    KeySelector: (t.Source Type),
    ElementSelector:(EntityShaperExpression:
        EntityType: Contact
        ValueBufferExpression:
            (ProjectionBindingExpression: EmptyProjectionMember)
        IsNullable: False
    )
    )' by 'RelationalProjectionBindingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core.

     

    I'm using a EF Core 3.1.4 that it connects to SQL Server 2018

     

  2. Answer
    Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1082 posts

    Posted 18 May 2020 Link to this post

    Hi, Dario,

    This is a known breaking change that Microsoft introduces with EF 3.1 and one of the solutions is to call ToList() before calling the ToDataSourceResult() or ToDataSourceResultAsync() extension methods.

    You can read more about it in this forum thread:

    https://www.telerik.com/forums/todatasource-throws-exception-using-ef-core-3-0-with-groups

    Kind Regards,
    Alex Hajigeorgieva
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top