【问题标题】:DbSortClause expressions must have a type that is order comparable. Parameter name: keyDbSortClause 表达式必须具有顺序可比的类型。参数名称:key
【发布时间】:2015-06-17 09:35:33
【问题描述】:

我正在尝试按字母顺序对名称列表进行排序。我以为我可以在我的 LINQ 语句上做到这一点,但事实并非如此,它给我带来了一个错误。有谁知道为什么会这样以及如何解决这个问题?

这是我的加入:

 public IQueryable<Supplier> GetAllSuppliersByClientWithClaims(int ClientID) {
            return (from s in db.Suppliers
                    where s.ClientID == ClientID
                    join h in db.Headers on new { a = s.ClientID, b = s.SupplierID } equals new { a = h.ClientID, b = h.SupplierID }
                    orderby s ascending
                    select s);
        }

这是视图的下拉菜单:

  @Html.DropDownListFor(m => m.ReportTypeOptions.First().ReportID, new SelectList(Model.ReportTypeOptions, "ReportID", "ReportName"), "Select Report", new { @class = "GRDropDown", @id = "ReportDD", onchange="myFunction()"})

【问题讨论】:

  • 要在哪个字段上升序排序??
  • 我想按 SupplierName 排序

标签: c# linq


【解决方案1】:

您通过entity 下订单。

您应该在entityproperty 之一上执行此操作

orderby s.SupplierName

当然也可以是多个属性:

 orderby s.SupplierName, 
         s.SupplierLastName,
         s.SupplierBirthDate descending

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多