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 ...
随机推荐
- 2018.08.17 洛谷[POI2010]GRA-The Minima Game(线性dp)
传送门 短代码神奇dp. 自己yy的思路居然1A了好高兴啊! 不难想到每个人选择的时候一定是取连续的最大的那一段数,自然需要先排序. 然后可以用dp[i]表示当前最大数是a[i]的时候先手可以获得的最 ...
- 2018.08.10 atcoder Median Sum(01背包)
传送门 题意简述:输入一个数组an" role="presentation" style="position: relative;">anan. ...
- Django入门与实践-第26章:个性化工具(完结)
http://127.0.0.1:8000/boards/1/topics/62/reply/ 我觉得只添加内置的个性化(humanize)包就会很不错. 它包含一组为数据添加“人性化(human t ...
- 14)settings.xml
1. User Level. ${user.home}/.m2/settings.xml 2. Global Level. ${maven.home}/conf/settings.xml <se ...
- matlab练习程序(生成希尔伯特曲线)
能够使用这样一条线遍历图像中所有的像素,不过这里没有这样做,而只是生成了这样一条曲线. 程序中h,w是最终图像的高和宽,n为希尔伯特曲线阶数. 这里如果n等于log2(h)或log2(w),则图像就全 ...
- EntityFramework 基本模式和Code-First的简单使用
1.Database-First Database First就是首先建立好数据库,或者存在现成的数据库也可以.然后在vs中添加ADO.Net实体数据模型,找到需要的数据库和表.它是以数据库设计为基 ...
- Scala类型检查与转换
Scala类型检查与转换 isInstanceOf:检查某个对象是否属于某个给定的类. asInstanceOf:将引用转换为子类的引用. classOf:如果想测试p指向的是一个Employee对象 ...
- POJ1511来回最短路
POJ1511 问你从1到其它点得所有最短路之和 与 其他点到1得所有最短路之和 得总和 思路很明确就是两次最短路,翻转一次地图就好了 一开始就是两次spfa之间处理好数据得更新管理就好 vect ...
- 层层递进Struts1(三)之Struts组成
这篇博客我们来说一下Struts的主要组成我们,通过前几篇博客,我们知道这个框架最重要的几个步骤:获取路径.封装表单.获取转向列表.转向逻辑处理.转向,与此对应的是:ActionServlet.Act ...
- Intellij Idea 14编译golang 插件
最近项目实在太赶了,很久没有写过博文了. 公司新配了一台笔记本电脑,原装win8的.于是又从linux回到了windows.不想用win命令行来搞go了,win下太折腾了.还是用一直使用的idea. ...