I have a database table with rows, each of which contains a sequential index. I want to select groups of rows that are sequentially based on this index column. For example, if I had rows with the following index values:
1 3 4 5 7 9 10 11 12 15 16
and I wanted to select all groups with 3 consecutive indices (this number will change). I would get the following groups:
3, 4, 5 9, 10, 11 10, 11, 12
Basically, I am trying to achieve something similar to the question asked here:
selection of sequential numbers using SQL query
However, I want to implement this with LINQ to Entities, and not with actual SQL. I would also prefer not to use stored procedures, and I don't want to do any ToList / looping approach.
Edit: Groups with more than the requested sequential elements need not be separated. that is, in the previous example, a result of 9, 10, 11, 12 would also be acceptable.
database linq linq-to-entities
knoia
source share