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.

error "Can only specify query options (orderby, where, take, skip) after last navigation" when fetching a List<string>的更多相关文章

  1. [转]Supporting OData Query Options in ASP.NET Web API 2

    本文转自:https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/suppor ...

  2. Error D8016 '/ZI' and '/Gy-' command-line options are incompatible

    使用vs运行工程时出现错误: Severity Code Description Project File Line Suppression StateError D8016 '/ZI' and '/ ...

  3. MySQL四种类型日志:Error Log、General Query Log、Binary Log、Slow Query Log

    MySQL Server 有四种类型的日志——Error Log.General Query Log.Binary Log 和 Slow Query Log. 第一个是错误日志,记录mysqld的一些 ...

  4. Error: clean-webpack-plugin only accepts an options object. See: https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional

    webpack中文文档中推荐这样使用,but 执行npm run build Error: clean-webpack-plugin only accepts an options object. S ...

  5. ### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: cn.xiaojian.blog.po.BlogType and java.lang.String ### Cause: java.lang.IllegalArgumentException: ...

    ### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: cn.xiaoj ...

  6. ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule

    解释:执行docker-compose up -d时出现ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule 原因:防火墙 ...

  7. R12.2 URL Validation failed. The error could have been caused through the use of the browser's navigation buttons

    EBS升级到R12.2.4后,进入系统操作老是报以下错误: 通过谷歌发现有人遇到相同的问题,并提供了解决方案. 原文地址:http://onlineappsdbaoracle.blogspot.com ...

  8. ✅问题:Rails.ajax的data不支持{}hash格式。必须使用string。 dataType的格式。

    Rails.ajax({ url: url, type: "PATCH", data: {"post":{"category_id":thi ...

  9. golang中使用mongodb的操作类以及如何封装

    mgo简介 mongodb官方没有关于go的mongodb的驱动,因此只能使用第三方驱动,mgo就是使用最多的一种. mgo(音mango)是MongoDB的Go语言驱动,它用基于Go语法的简单API ...

随机推荐

  1. C#中验证sql语句是否正确(不执行语句)

    SET PARSEONLY检查每个 Transact-SQL 语句的语法并返回任何错误消息,但不编译和执行语句.SET PARSEONLY { ON | OFF }当 SET PARSEONLY 为 ...

  2. ArcGIS Desktop python Add-in 测试一个插件

    a)制作一个插件文件 先找到工作目录,双击运行makeaddin.py脚本.这个脚本拷贝所有插件需要的文件和文件夹并在工作目录形成一个压缩文件.该压缩文件名为工作目录名称加上".esriad ...

  3. C语言中交换两个数值的方法

    //方法1    int  one = 1;    int two = 2;    int temp = 0;    temp = one;    one = two;    two = temp;  ...

  4. struts2从浅至深(五)上传与下载

    1.编写上传页面 2.编写动作方法 import java.io.File;import java.io.IOException; import javax.servlet.ServletContex ...

  5. C++中的矩阵运算

    C++中的矩阵运算 1. 2阶矩阵的逆矩阵公式

  6. 【LeetCode】 Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  7. 设计模式之单件模式(Singleton Pattern)

    一.单件模式是什么? 单件模式也被称为单例模式,它的作用说白了就是为了确保“该类的实例只有一个” 单件模式经常被用来管理资源敏感的对象,比如:数据库连接对象.注册表对象.线程池对象等等,这种对象如果同 ...

  8. ASP.NET Core使用EPPlus操作Excel

    1.前言 本篇文章通过ASP.NET Core的EPPlus包去操作Excel(导入导出),其使用原理与NPOI类似,导出Excel的时候不需要电脑上安装office,非常好用 2.使用 新建一个AS ...

  9. C# 一些代码小结--使用文件记录日志

    C# 一些代码小结--使用文件记录日志 public class FaceLog { public static void AppendInfoLog(string errMsg) { try { s ...

  10. C# 32位程序,申请大内存,附dome(wpf),亲测可用

    1.我是vs2017,在选装vs的时候,需要安装c++模块,因为申请大内存的必要exe存放在vc的某个目录(下面会给出详细的地址)下的 2.安装完成在vs的安装目录可找到这个文件,我是社区版本的,如果 ...