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 ...
随机推荐
- 打开yii2控制台命令
1.在控制台中切换到yii2控制台入口文件的工作路径.如:C:\users\2016-01>D:www\blogdemo\yii
- 如何用命令行将我的Phonegap环境更新到最新版本?
从npm安装的Phonegap(version > 3.0),更新命令如下 npm update -g phonegap 检查当前本机环境的最新版本 phonegap -v 检查npm的最新ph ...
- Codeforces807 C. Success Rate 2017-05-08 23:27 91人阅读 评论(0) 收藏
C. Success Rate time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- The Activities of September
- Two ways to see predicates added by VPD or FGAC
http://www.bobbydurrettdba.com/2012/07/17/two-ways-to-see-predicates-added-by-vpd-or-fgac/ Two ways ...
- leetcode-爬楼梯(动态规划)
假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解释: 有两 ...
- Android-Java-IO流概述
IO:I:Input输入 O:Output输出 IO流: IO:用于处理设备上数据的一种技术,处理设备上数据包括(Input / Output) ,设备指的是:内存,硬盘,U盘,打印机,等等..... ...
- Transaction And Lock--唯一索引下INSERT导致的死锁
背景: 曾经的一位同事问我:"数据库只有并发INSERT 操作,会造成死锁么?",我没有太多思考地回答"不会",但真的不会吗? 测试: --========== ...
- DBCC--CHECKDB--不可被替代的原因
CHECKSUM不能发现的两类问题 1. 发生在内存中的页错误,如内存损坏+第三方程序修改等 2. MS SQL Server潜在BUG导致的逻辑错误,该类错误可以使用重建索引或重建约束来修复 CHE ...
- ASP.NET在请求中检测到包含潜在危险的数据,因为它可能包括 HTML标记或脚本
背景:程序迁移到新的服务器上,在程序进行修改操作时,提示包含危险数据.然而在旧服务器上却没有问题,我猜想的可能是,新服务器IIS安装的ASP.NET版本框架高于以前的IIS上的版本框架,导致web.c ...