2

I have a sorting problem with kendo ui grid. I have a Entity class Port, in partial class I added additional property:

public partial class Port {

    [NotMapped]
    [XmlIgnore]
    [ScriptIgnore]
    public string CountryName { get; set; }
}

I am using this property in other program parts. In controller I have:

    public ActionResult Index()
    {
        if (!CanViewPorts())
            return new EmptyResult();
        ViewBag.CanEditPorts = CanEditPorts();
        return View();
    }

    public ActionResult Ports([DataSourceRequest] DataSourceRequest request)
    {
        if (!CanViewPorts())
            return new EmptyResult();
        var all = _classificatoryService.GetAllPorts();
        return Json(all.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

I'am using method Ports in my view to populate kendo ui grid. My view:

@(Html.Kendo().Grid<Port>()
      .Name("Ports")
      .ToolBar(toolbar => toolbar.Template(Toolbar().ToString()))
      .Columns(columns =>
      {
          columns.Bound(c => c.PortId);
          columns.Bound(c => c.Code);
          columns.Bound(c => c.Name);
          columns.Bound(c => c.AlternativeName);
          columns.Bound(c => c.SubDivision);
          columns.Template(@<text></text>).ClientTemplate("<a class='k-button k-button-icontext' href='" + Url.Action("Details", "Port") + "/#=PortId#'><span class='glyphicon glyphicon-edit mr5'></span>Details</a>").Width(110);  //"<#=PortId#>"
          columns.Template(@<text></text>).ClientTemplate("<a class='newPortBtn k-button k-button-icontext' href='" + Url.Action("NewPort", "Port") + "/?portId=#=PortId#'><span class='glyphicon glyphicon-edit mr5'></span>Edit</a>").Visible(canEditPorts).Width(110);
      })
                .Sortable()
                .ColumnMenu()
                .Filterable()
                .Pageable(pageable => pageable
                    .Refresh(true)
                    .PageSizes(true)
                    .ButtonCount(5))
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Model(model => model.Id(x => x.PortId))
                        .Read(read => read.Action("Ports", "Port"))
                    .Sort(sort => sort.Add(x => x.ChartererId).Descending())
                        .Create(c => c.Action("NewPort", "Port"))

                ))

As you can see I'a not using additional property Countryname in this view.

Ok, grid gets ports and show it properly. Then I'am trying to sort and click column header.

First click (ASC) - Ok, grid sorted by this column in ascending order.

Second click (DESC) - Ok, grid sorted by this column in descending order.

Third click (unsort) - Grid must be unsorted, but I have 500 (Internal Server Error).

In chrome/Network/Preview I have:

Server Error in '/' Application. The specified type member 'CountryName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

How to fix this problem?

Piotr Leniartek
  • 1,177
  • 2
  • 14
  • 33
Oblomingo
  • 668
  • 3
  • 10
  • 29
  • There are many other examples of this question on SO that have been answered. [[1](http://stackoverflow.com/questions/19997792/the-specified-type-member-offset-is-not-supported-in-linq-to-entities)] [[2](http://stackoverflow.com/questions/11584660/the-specified-type-member-is-not-supported-in-linq-to-entities-only-initializer)] [[3](http://stackoverflow.com/questions/25867470/the-specified-type-member-userscount-is-not-supported-in-linq-to-entities)] – Brett Mar 02 '15 at 15:30

0 Answers0