【问题标题】:Cannot convert lambda expression to type "string" because it is not a delegate type?无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型?
【发布时间】:2014-02-14 11:31:18
【问题描述】:
var date = DateTime.Now.AddMonths(-3);
buyers.OrderBy(x => x.Visits.Where( y => y.VisitStart > date).Count());

在 orderby 表达式中,我得到无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型。 代码应该做的是按我的“买家”在过去 3 个月内的“访问次数”对他们进行排序。

Buyers 是具有访问列表的实体,Visit 具有 DateTime VisitStart

如果有什么不同,买家是IQueryable<Buyer>,访问是ICollection<Visit>

【问题讨论】:

  • 什么是buyersVisits?和VisitStart?
  • 对不起伙计们。刚刚编辑
  • 您确定 this 代码会给您错误吗?
  • 如果有什么不同的话,buyers 是 IQueryable 并且 Visits 是 ICollection,很可能

标签: c# linq lambda


【解决方案1】:

实际代码是

buyers.OrderBy(x => x.Visits.Where( y => y.VisitStart > date).Count() , sort.Direction);

问题是 sort.Direction,但我很愚蠢,认为这没关系。 Sort 是 GridSortOptions 的类型,我用它来手动排序一些东西。

抱歉问题,我明显漏掉了最重要的部分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多