LINQ to JSON:InvalidOperationException:Lambda参数不在范围内 [英] LINQ to JSON: InvalidOperationException: Lambda Parameter not in scope
本文介绍了LINQ to JSON:InvalidOperationException:Lambda参数不在范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行LINQ to JSON的示例代码(如下所述),但它给了我以下错误
I am trying the execute the sample code of LINQ to JSON (mentioned below) but it is giving me following error
堆栈跟踪:
[InvalidOperationException:Lambda参数不在范围内]
[InvalidOperationException: Lambda Parameter not in scope]
我正在执行的代码是:
JObject rss =
new JObject(
new JProperty("id", "James Newton-King"),
new JProperty("name", "http://james.newtonking.com"),
new JProperty("data", "James Newton-King's blog."),
new JProperty("children",
new JArray(
from p in mwsysbot.Software
where p.SoftwareName == name
select new JObject(
new JProperty("id",p.SoftwareUUID),
new JProperty("name", p.SoftwareName)
)
)
)
);
此外,当我删除"new JProperty("name",p.SoftwareName)"行时,代码将完美执行.
Also when I remove line "new JProperty("name", p.SoftwareName) " the code executes perfectly.
为什么?
推荐答案
我尝试了这个,对我有用...
I tried this and it worked for me...
IQueryable<Software> soft = (from s in mwsysbot.Software
select s).ToList();
JObject rss =
new JObject(
new JProperty("id", "James Newton-King"),
new JProperty("name", "http://james.newtonking.com"),
new JProperty("data", "James Newton-King's blog."),
new JProperty("children", new JArray(
from m in soft
select new JObject(
new JProperty("id",m.SoftwareName),
new JProperty("name", m.SoftwareName),
new JProperty("children",new JArray())
)
))
);
我不知道原因!
好像我们只能在上述位置使用"List"数据结构吗?
Is it like we can use only the "List " data structure in the above place ?
这篇关于LINQ to JSON:InvalidOperationException:Lambda参数不在范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文