zoukankan      html  css  js  c++  java
  • error "Can only specify query options (orderby, where, take, skip) after last navigation" when fetching a List<string>

    Question

    I use OData v3 and WCF in visual studio 2012.

    I want to return List<string> using the following query, but got error "Can only specify query options (orderby, where, take, skip) after last navigation"

    List<string> output = (from g in SFPServices.modelService.TGalleries                         

    where g.IsEnabled                         

    select g.Title).ToList();

    After some research I was only able to get the query to execute without problem, below is where i am stuck:

    List<string> output = new List<string>();

    var temp = (from g in SFPServices.modelService.TGalleries                         

    where g.IsEnabled                         

    select new { g.Title });

    Could someone please help populate the string list "output" with the query result? Or share a better way to generate the output?

    thanks in advance

    ANSWER:

    output = temp.AsEnumerable().Select(t => t.Title).ToList();

    That should do it. You can obviously write this in a single statement (no need for the temp variable). The trick is the AsEnumerable. The LINQ provider will try to translate everything before it (so your entire temp) into an OData query. But OData query only supports select if it's a subset of an entity, it can't change a query which returns an entity into a query which returns a string. But once you add the AsEnumerable, the query will execute there, and the rest (to the right) will be executed locally using LINQ to Objects which can handle any query just fine.

  • 相关阅读:
    java 23种设计模式 深入理解
    ORACLE 一条记录 某字段值以';'拆分为多条记录
    rabbitmq集群故障恢复
    ORACLE 时间加减操作
    Asp.net MVC Razor输出字符串方法(js中嵌入razor)
    C# ToString() 数据格式
    DOM的整个知识体系
    EF 连接模式
    EF Code First 数据库连接方式
    使用border实现提示框的
  • 原文地址:https://www.cnblogs.com/xixifusigao/p/3944962.html
Copyright © 2011-2022 走看看