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 trying to use Lightspeed together with the Telerik MVC grid (Telerik MVC stuff here). The grid *should* just retrieve the necessary rows for the current page. However it is retrieving all rows from the database and then filtering them. This will be a problem with larger datasets. The grid takes an IEnumerable. At a later stage IEnumerable.AsQueryable is called, and then the data is passed to the following extension method: public static IQueryable Take(this IQueryable source, int count)
I am providing data as follows: // GET: /Acc/ToDoItems/ I am using LS 2.2 from mid Oct.
Any ideas where this is going wrong? I can provide a test app if you want. Sean |
|
|
We think what may be going on here is that something is enumerating the query results before passing them to the Skip and Take extension methods, so that the AsQueryable call is just creating a "dummy" IQueryable over the already enumerated collection. Could you put a debugger on the Skip or Take function and see what the concrete type of source is please? Thanks! |
|
|
Source is + source {System.Linq.OrderedEnumerable`2[CmsModels.Entities.ToDoItem,System.Nullable`1[System.DateTime]]} System.Linq.IQueryable {System.Linq.EnumerableQuery<CmsModels.Entities.ToDoItem>} |
|
|
Okay, EnumerableQuery is the (internal .NET) class created by the AsQueryable method when you call it on something that is only IEnumerable, not IQueryable. So this looks like something is enumerating the results between you creating the query and it having AsQueryable called on it. Our guess would be that this is something internal to the Telerik grid (or the View method?) but it might also be something in your code -- we don't know what is calling the Skip and Take methods or where AsQueryable is being called so it's hard for us to offer a guess. Does this give you any ideas? |
|
|
I can't find anywhere enumerating over the data before the Take call. If I change my controller as follows // GET: /Acc/ToDoItems/ Then both newItems and limited are EnumerableQuery. I haven't called any enumeration in there. Also the "select xxx" query is called before the var newItems =... line. + newItems {System.Linq.OrderedEnumerable`2[CmsModels.Entities.ToDoItem,System.Nullable`1[System.DateTime]]}
|
|
|
Ah, hang on, I think I see it. CmsUser.ToDoItems is a child collection, i.e. an EntityCollection, not an IQueryable. When you reference a child collection, LightSpeed materialises the whole child collection. Sorry for leading you astray, I missed this before. The fix is to rewrite your query so as to use a query over the child collection rather than the collection contents. To do this, use the Entity.Query() extension method: from i in CmsUser.Query(u => u.ToDoItems) ... You may need to upgrade to a recent nightly build for this, and will need to import the Mindscape.LightSpeed.Linq namespace. |
|
|
That was the problem alright, but it means that child collections are substantially less useful than I had thought :( |
|