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. maven随笔

    1.在我们项目顶层的POM文件中,我们会看到dependencyManagement元素.通过它元素来管理jar包的版本,让子项目中引用一个依赖而不用显示的列出版本号.Maven会沿着父子层次向上走, ...

  2. Django-组件

    https://www.cnblogs.com/yuanchenqi/articles/8034442.html

  3. 怎么备份VMware虚拟磁盘文件或移植到其他虚拟机

    原文:http://jingyan.baidu.com/article/a681b0de17b3173b1843468f.html 方法/步骤     第一种方法:直接复制本地主机磁盘下的虚拟磁盘文件 ...

  4. iphone“连接到icloud是出错”的可能原因

    百度没能解决"连接到icloud是出错",突然发现是因为禁止了"设置"访问WIFI和蜂窝网络(第三张图所示). ​

  5. ORBSlam with ROS

    ...相机标定 calibration 基本就是做CV 的常识 ORBSlam源码:

  6. PHP编译安装完成之后没有'php.ini'文件的处理方法

    在我们编译安装PHP的时候,编译安装完成是不会自动生成php.ini文件的,所以需要我们手动生成. 1.通过命令行确定php.ini文件的位置 php -r "phpinfo();" ...

  7. Oracle 在not in中使用null的问题

    http://www.linuxidc.com/Linux/2012-07/66212.htm 以前还专门小总结过一下Oracle中关于NULL的一些问题,碰巧今天在看书的过程中又看到了另外一个以前没 ...

  8. EBS 中查看LOV中的查询语句

    http://blog.csdn.net/shishun123/article/details/6874824 一直有实施顾问询问我XXForm的XX LOV是什么逻辑,取数SQL是什么来着,以前比较 ...

  9. Delphi 中 FindWindow 和 FindWindowEx 的语法和用法

    FindWindow(lpClassName,        {窗口的类名}lpWindowName: PChar {窗口的标题}): HWND;              {返回窗口的句柄; 失败返 ...

  10. Windows 8/8.1 及 Windows Phone 8 应用神器 - APP Producer

    继 App studio 以及  Project Siena 之后 微软再次打造应用生成器 APP Producer,这个版本的应用生成器功能相对比之前两个版本要简单许多,更适合入门并且真正的支持全平 ...