Summing up the problem in a single line for clarity as suggested:
I want to find all the things that have different values for some field and are less than a week apart (based on another field)
Let's say I have a Users
table and a User
class.
Each User
has the following fields:
SignUpDate
a non-nullDateTime
fieldUserType
an int field, for this question let's say it's either1
or0
I'd like to select all the couples of users that signed up less than 7 days apart and have a different user type.
My current (miserable) attempt included an OrderBy(r=>r.SignUpDate)
and a .ToList
which wasn't a big deal since the number of users for every 2 weeks is not large. (I grabbed all the users from that with overlapping weeks and compared the data).
However, I find my current solution pretty poor. I have no idea what's the correct way to approach this.
I think the core problem here is that I don't know how to address the concept of 'selecting every two corresponding records' in LINQ to Entities after an ordering.
Any help much appreciated, I'm interested in how I would be able to solve this sort of problem without starting my own question in the future.
Example input
SignUpDate UserType
------------------------------------
2008-11-11 1
2008-11-12 0
2008-11-13 0
2008-12-13 0
2008-12-15 1
Example output
Any meaningful way to indicate that the problematic pairs were:
2008-11-11 1
2008-11-12 0
(Different by a day and different type)
And
2008-12-13 0
2008-12-15 1
(Different by two days and different type)
Here is a related SQL solution I found.