【问题标题】:Ravendb Lambda (OrderBy) getting NotSupportedExceptionRavendb Lambda (OrderBy) 获取 NotSupportedException
【发布时间】:2012-09-27 13:56:19
【问题描述】:

所有...

我正在使用 RavenDB 嵌入式,使用 NuGet 和 MVC 3 的最新稳定版本。

    public JsonResult GetStudents(GridFilter filter)
    {
        using (var session = _store.OpenSession())
        {
            var students = session.Query<Student>();
            students.OrderBy(x => x.FirstName);

            return Json(students.ToList());
        }
    }

此代码不会中断。它也不按 Student.FirstName 排序。我查看了 RavenQueryInspector(将鼠标悬停在学生集合上),发现以下内容...

AsyncDatabaseCommands = '(((Raven.Client.Linq.RavenQueryInspector<UMA.KendoGrid.Entities.Student>)(students))).AsyncDatabaseCommands' threw an exception of type 'System.NotSupportedException'

如果我这样做了

var students = from x in session.Query<Student>()
        orderby x.FirstName descending
        select x;

效果很好。首先,我不明白为什么在使用 long linq 语法时使用 lambda 会失败。我真正需要的是按任何领域过滤学生,因为我使用的是具有排序能力的网格。我想使用 Microsoft 的 System.Linq.Dynamic 文件按字符串名称排序,这样我就可以按排序集合中传递的任何字段进行排序。

但是,要开始使用,我想我需要弄清楚为什么我的 RavenDB 嵌入式版本不允许我使用 lambda 表达式。有人可以帮忙吗?

【问题讨论】:

  • 我已经在 text 中回答了这个问题 - 但标题似乎完全不相关......(asp.net-mvc-3 也是如此。)
  • 我从最新的 RavenDB 嵌入式降级到 1.0.701,它看起来也无法正常工作。
  • 当我查看 RavenDB 结果时,AsyncDatabaseCommands 属性抛出了我显示的异常。这就是为什么我认为这是 RavenDB 的问题。

标签: asp.net-mvc-3 linq lambda ravendb


【解决方案1】:

关于此声明:

students.OrderBy(x => x.FirstName);

...您忽略了调用的结果。这是“忽略字符串调用的结果”错误的 LINQ 等价物:

text.Substring(5, 10);

LINQ 调用永远不会改变它们被调用的内容——它们会返回一个经过适当转换的新集合。所以你想要:

students = students.OrderBy(x => x.FirstName);

或者,更好:

var students = session.Query<Student>.OrderBy(x => x.FirstName);

【讨论】:

  • 哇...多么尴尬...谢谢你指出这一点:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 2011-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多