error "Can only specify query options (orderby, where, take, skip) after last navigation" when fetching a List<string>
2014-08-29 14:59
2839 查看
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: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB
- Only one expression can be specified in the select list when the subquery is not introduced with(求助)
- When I write #include <qdom.h> it gives error "no such file or directory".
- To.String("X2")、 list的skip、take的用法
- JavaSE8基础 LinkedList<String> getFirst getLast 获取首尾元素
- query for a List<String> using DBUtils
- Spring JdbcTemplate # queryForList(String sql , Class<T> elementType)
- SharePoint上传文件显示在label 页面Session["demo"] = new List<String>();(实现)
- how to query for a list<String> in jdbctemplate?--转载
- 从客户端(textarea="<p>wewqe</p>")中检测到有潜在危险的 Request.QueryString 值。
- List<string> tmp=new List<string>() string s="北京“的个数
- ibatis 返回list<String[]>----resultClass="hashMap" 可以实现
- Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named
- Only one expression can be specified in the select list when the subquery is not introduced with EXI
- $lt(<) $lte(<=) $gt(>) $gte(>=) $ne(!=) $in $not $size $where limit(5).skip(5).sort({"number" : -1}
- Spring JdbcTemplate的queryForList(String sql , Class<T> elementType)易错使用--转载
- 编译错:The method createSqlQuery(String, List<Object>) is ambiguous for the type
- spring JdbcTemplate().queryForList(String sql, Class<T> elementType)
- After the clone, you can list the tags with git tag -l and then checkout a specific tag: git checkout tags/<tag_name>
- Only one expression can be specified in the select list when the subquery is not introduced with EXI