LINQ TO SQL - Skip/Take not working as expected
I've got an IQueryable repository (admittedly this is the first time I've tried this) and I can't seem to get it to pull the correct data using Skip(1).Take(1)
Here's the repository
Public Function GetActivity() As IQueryable(Of ActivityLog) Implements IActivityLogRepository.GetActivity
Dim activity = (From a In dc.ActivityLogs
Order By a.ActivityDate Descending
Select a).AsQueryable
Return activity
End Function
开发者_JAVA技巧
And here's the Service
Public Function GetUsersLastActivity(ByVal UserID As Integer) As ActivityLog Implements IActivityLogService.GetUsersLastActivity
Return _ActivityLogRepository.GetActivity().Where(Function(a) a.UserID = UserID).Skip(1).Take(1)
End Function
The problem is that it's returning the FIRST record in the Order By clause and not the SECOND.
Can anyone tell me what I'm doing wrong here?
Are you sure it is? Why don't you separate the calls and look at the results in debug mode...
var list = _ActivityLogRepository.GetActivity().Where(Function(a) a.UserID = UserID);
var skipped = list.Skip(1);
var taken = skipped.Take(1);
return taken;
精彩评论