Entity Framework allows you to choose a range.

c# entity-framework linq-to-entities

Question

I'm having trouble attempting to improve our listview's page-based performance.

I want the entity framework to do a select statement but only return the items from one page of the listview as the range of the results.

I looked for this on Google but came up empty-handed. I just discovered that I can. ToList(). GetRange(start index, finish index), however it would load every item into memory, which I would want to avoid.

Can someone let me know whether this is possible? Given that our listview must be reusable, I don't want to utilize a stored method, view, or anything similar.

Thanks!

1
7
5/4/2011 7:09:18 AM

Accepted Answer

You need should be able to use.Take(x).ToList()

I'm sorry, but.Skip(startPosition).Take(numberOfItems).ToList()

16
5/4/2011 7:12:32 AM

Popular Answer

In order to avoid loading the whole collection before applying filters, use Query() before Load() if you are not utilizing lazy loading:

context.Entry(blog) 
    .Collection(b => b.Posts) 
    .Query() 
    .Skip(startPosition)
    .Take(numberOfItems)
    .Load()
    .ToList(); 

It is often recommended to disable lazy loading for the navigation property when utilizing the query approach. This is necessary because, in the alternative, the lazy loading method may automatically load the full collection either before or after the filtered query has been run.

the following number: http://msdn.microsoft.com/en-us/data/jj574232.aspx



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow