Print Page | Close Window

Issue with query using skip and take after an entity is marked as deleted

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2125
Printed Date: 10-Jun-2026 at 7:09pm


Topic: Issue with query using skip and take after an entity is marked as deleted
Posted By: akukucka
Subject: Issue with query using skip and take after an entity is marked as deleted
Date Posted: 03-Sep-2010 at 12:03pm
We've created a pager control that feeds a DataGrid a dynamic number of records instead of an entire table. It fetches records based on the page it's on and the number of records to display per page using the Skip and Take methods.

We're seeing some interesting behavior after a record in a page is marked as deleted.  At that point, the pager will attempt to refresh itself and fetch the contents using the Skip and Take methods again.  For some reason though,  the query will sometimes incorrectly return 0 results.

I've been able to reproduce this behavior without the pager:
            var random = new Random();
            var count = EntityManager.Consultants.Count();

            var skippedAndTaken =
                EntityManager.Consultants.OrderBy(x => x.ConstId).Skip(count - 40).Take(20).ToList();
            var randomEntity = skippedAndTaken.Skip(random.Next(20)).Take(1);
            randomEntity.FirstOrDefault().EntityAspect.Delete();
            var skippedAndTakenAgain =
                EntityManager.Consultants.OrderBy(x => x.ConstId).Skip(count - 40).Take(20).ToList();
The skippedAndTakenAgain variable never contains any records when I run this code.  This issue appears to happen frequently toward the 'end' of the table (in the example I'm skipping all but the last 40 records and then taking 20).
I've run similar code using Entity Framework and it works correctly.
Has anyone else seen this issue?  Perhaps its an issue with caching or something?
Thanks!
Adam



Replies:
Posted By: akukucka
Date Posted: 08-Sep-2010 at 5:33am
Anyone???


Posted By: sbelini
Date Posted: 08-Sep-2010 at 9:47am
Hi Adam,
 
I'm investigating your issue and will follow up with you soon.


Posted By: sbelini
Date Posted: 09-Sep-2010 at 3:04pm
The query is returning 0 results because you are running it against the cache and once it skips a x number of records, there is nothing left to take.
The "deleting" part takes no role in this behavior.
 
Try using DataSourceOnly QueryStrategy:
 
var skippedAndTakenAgain = EntityManager.Consultants
                                                              .With(QueryStrategy.DataSourceOnly)
                                                              .OrderBy(x => x.ConstId)
                                                              .Skip(count - 40)
                                                              .Take(20)
                                                              .ToList();


Posted By: akukucka
Date Posted: 10-Sep-2010 at 6:29am
Thanks for the response!

I'm not convinced that the delete is taking no part in this behavior.  The skip/take scheme we're utilizing works great for every page we create until delete is introduced.

Also, say I delete a record from page 23 (of a total of 25 pages).  Upon refresh, the query for page 23 yields no results.  Page 24 may or may not yield any results, but page 25 (the last page) does.

QueryStrategy.DataSourceOnly does work for me in this situation IF I commit each delete (which I did not plan on doing).  But it would really be nice to utilize the cache whenever possible and speed things up for the user.

I really have reproduced this skip/take query in EF and it did return the correct results after a delete...



Print Page | Close Window