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.
error "Can only specify query options (orderby, where, take, skip) after last navigation" when fetching a List<string>的更多相关文章
- [转]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 ...
- Error D8016 '/ZI' and '/Gy-' command-line options are incompatible
使用vs运行工程时出现错误: Severity Code Description Project File Line Suppression StateError D8016 '/ZI' and '/ ...
- MySQL四种类型日志:Error Log、General Query Log、Binary Log、Slow Query Log
MySQL Server 有四种类型的日志——Error Log.General Query Log.Binary Log 和 Slow Query Log. 第一个是错误日志,记录mysqld的一些 ...
- 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 ...
- ### 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 ...
- 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 原因:防火墙 ...
- 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 ...
- ✅问题:Rails.ajax的data不支持{}hash格式。必须使用string。 dataType的格式。
Rails.ajax({ url: url, type: "PATCH", data: {"post":{"category_id":thi ...
- golang中使用mongodb的操作类以及如何封装
mgo简介 mongodb官方没有关于go的mongodb的驱动,因此只能使用第三方驱动,mgo就是使用最多的一种. mgo(音mango)是MongoDB的Go语言驱动,它用基于Go语法的简单API ...
随机推荐
- 将IP地址转化为整数
$ip = 'IP地址';echo $intip = sprintf('%u',ip2long($ip)); //转换为无符号整型echo long2ip($intip);//将整型转换为ip
- 一组RS485设备操作命令
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ZNJM ...
- C++ 动态分配 和 内存分配和内存释放
动态分配 动态分配可以说是指针的关键所在.不需要通过定义变量,就可以将指针指向分配的内存.也许这个概念看起来比较模糊,但是确实比较简单.下面的代码示范如何为一个整数分配内存: int *pNumber ...
- UVa 508 Morse Mismatches (模糊暴力)
题意:莫尔斯电码,输入若干个字母的Morse编号,一个字典和若干编码.对于每个编号,判断它可能的是哪个单词, 如果有多个单词精确匹配,输出第一个单词并加一个“!”:如果无法精确匹配,那么在编码尾部增加 ...
- centos下安装visual studio code出现can't find libXss.so.1,出现这在类似怎么查找相关包
在安装visual studio code时候.出现libXss.so.1被依赖,这个so文件要查看是属于那个包,通过此命令repoquery --nvr --whatprovides libXss. ...
- noip第9课作业
1. 打印乘法表 [问题描述] 用for循环实现输出1至9的乘法表 [样例输出] 1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4 ...
- crosss compile VLC with OpenMAX on ARM board(RockChip RK3399),in order to use Hard Acceleration when decode video
reference:http://www.x90x90x90.com/en/raspberry-pi-3-howto-compile-vlc-with-hardware-acceleration/ 1 ...
- spark ml 的例子
一.关于spark ml pipeline与机器学习 一个典型的机器学习构建包含若干个过程 1.源数据ETL 2.数据预处理 3.特征选取 4.模型训练与验证 以上四个步骤可以抽象为一个包括多个步骤的 ...
- JSP、Servlet中get请求和post请求的区别总结
在学习JavaWeb最初的开始阶段,大家都会遇到HttpServlet中的doGet和doPost方法.前两天看<Head First Servlets & JSP>看到其中讲关于 ...
- CxGrid导出Excel时清除颜色的设置
CxGrid导出Excel时清除颜色的设置 (2011-04-25 16:33:23) 转载▼ 标签: it 分类: Delphi http://www.radxe.com/?p=170 cxgrid ...