5

I am trying the execute the sample code of LINQ to JSON (mentioned below) but it is giving me following error

Stack Trace:

[InvalidOperationException: Lambda Parameter not in scope]

Code I am executing is:

      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)         
                    )
                  )
                 )
               );

Also when I remove line "new JProperty("name", p.SoftwareName) " the code executes perfectly.

Why?

1
  • 1
    Could you post a stacktrace of your exception? I'm pretty sure that error isn't coming from Json.NET. Commented Jun 16, 2009 at 10:53

2 Answers 2

3

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())
                             )
                         ))


             );

I dont know the reason !

Is it like we can use only the "List " data structure in the above place ?

Sign up to request clarification or add additional context in comments.

Comments

0

Linq could try to lazy-load the SoftwareName. Try using a DTO and eager-load the parameter name before creating the new object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.