0

I'm using jqGrid and I have a problem getting Dynamic Linq to work. I used NuGet to install Dynamic and added "using System.Linq.Dynamic;".

Using VS 2010 Pro, MVC 3.0

This works:

var s = context.testdata;
var c = s.Count();

c shows 5136 items.

But I cannot get the dynamic approach to work:

var s = context.testdata.OrderBy("id asc");

I get this error message:

'id' could not be resolved in the current scope or context. 
Make sure that all referenced variables are in scope, 
that required schemas are loaded, and that namespaces are referenced correctly.

This however does work:

var s = (from ss in context.testdata
                      orderby ss.id
                      select ss).ToList();
var c = s.Count();

Again I get all 5136 items.

I've got the code from here: http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
and here:
http://www.timdavis.com.au/code/jquery-grid-with-asp-net-mvc/

Any idea what I am doing wrong?

Oliver Kötter
  • 1,006
  • 11
  • 29
  • try this `context.testdata.OrderBy("id")` – Wahid Bitar Jun 19 '12 at 11:25
  • @Wahid: No, same error. But according to the demos of jqGrid asc or desc should work. – Oliver Kötter Jun 19 '12 at 11:31
  • Try to add the the DynamicLibrary manually http://msdn.microsoft.com/en-us/vstudio//bb894665.aspx – Wahid Bitar Jun 19 '12 at 11:52
  • I tried it but I get the same error. I tried deleting the library and get the same error, I think the library is not used at all. What else is needed besides adding the lib and the using statement? The demos from the links above work fine for me. I even recreated a new simple db and model and still get the same. I also recreated my code from scratch and still get it. – Oliver Kötter Jun 19 '12 at 14:56

1 Answers1

0

OK, found the solution here:
Strange Exception thrown using Dynamic Linq Entity Framework Query

This works:

var s = context.testdata.OrderBy("it.id asc");
Community
  • 1
  • 1
Oliver Kötter
  • 1,006
  • 11
  • 29