This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am using the Telerik MVC grid control again. When I try to use sorting, I get an "Object reference not set to an instance of an object." error. Full stack trace is at the bottom of the post. I am using the latest 2.2 nightly build. The error occurs in the extension method public static void Each<T>(this IEnumerable<T> instance, Action<T> action)
Instance is + instance {Mindscape.LightSpeed.Linq.LinqQuery<CmsModels.Entities.ToDoItem>} System.Collections.Generic.IEnumerable<CmsModels.Entities.ToDoItem> {Mindscape.LightSpeed.Linq.LinqQuery<CmsModels.Entities.ToDoItem>} I retrive my objects using private IEnumerable<ToDoItem> GetTodoItems(string filter)
Stack trace Object reference not set to an instance of an object. |
|
|
Having a bit of trouble reproducing this one I'm afraid. I noticed there's a Take in your stack trace which isn't part of the original query in your code -- is that something that Telerik adds? Or part of GetUserToDo? I tried adding a Take to our test case but still couldn't get an exception. Do you have access to the full query as it stands when Telerik enumerate it (i.e. after they've added their clauses)? Thanks! |
|
|
The Take is added by Telerik as part of the paging. The sorting occurs as follows: public IQueryable Sort() After this, query._expression is {value(Mindscape.LightSpeed.Linq.LinqQuery`1[CmsModels.Entities.ToDoItem]).Select(e => e).Where(t => (t.UserId = Convert(value(CmsModels.Repositories.AccRepository+<>c__DisplayClass8).user.Id))).Where(i => Not(i.CompletedDate.HasValue)).OrderBy(i => i.DueDate).OrderBy(item => IIF((item != null), item.ClaimReference, null))} I have tried removing my initial ordering, but that doesn't help. |
|
|
Thanks for all the detailed info! I noticed in the final expression this: OrderBy(item => IIF((item != null), item.ClaimReference, null) Any idea where this clause is coming from? I also noticed this: Where(t => (t.UserId = Convert(value(CmsModels.Repositories.AccRepository+<>c__DisplayClass8).user.Id))) I'm not quite sure what's going on inside AccRepository here -- a closure or an iterator I guess (or possibly an anonymous type, though it doesn't look like one). Can you shed any light on what might be providing this .user property? Or maybe post the definition of AccRepository.GetUserToDo? Finally, our horrible forum software has removed the details of CreateLambda... and Expression.Quote... in the Sort method you posted. Could you perhaps copy the Sort() body into a text file and attach it via the Options tab. Sorry to be annoying, this is a problem with the forum software which I need to make JD fix... Thanks for your help in reproducing this! |
|
|
The orderby is coming from the grid when I click on a header to order it. Without the order by, the code works, with it, I get the error.
AccRepository public IQueryable<ToDoItem> GetUserToDo(User user) |
|
|
Any ideas? This I get this problem on every grid. |
|
|
Hi Sean, Looks like the reason for the exception is the IFF (conditional) based OrderBy being added in to the query and this is unsupported in our LINQ provider. Looking at it though, the inclusion of that seems a bit odd - if I am reading it correctly it should just be adding a OrderBy for the property rather than needing a conditional in there - is that the column you are sorting on? (there are 2 order bys in the example you specified above..)
Jeremy |
|
|
That is the column I am sorting by. I can remove my initial sort but I still get the same error. |
|
|
Thanks Sean - Ill have a look at what the Telerik control is doing here to try and understand why it needs to build up its ordering query this way rather than just using a normal OrderBy(property). Will let you know what I find. |
|
|
Thanks. However don't get too exercised over it. After another 1/2 day spent with the grid I am about ready to give up and go back to the MvcContrib grid.
|
|