I have dropped on this question: SQL query to find Missing sequence numbers. I want to achieve the same thing but with LINQ to SQL.
To recap: I have a table with ids like 1,2,4,5,10,11,12,15, [...]. I want the unused ids 3,6,7,8,9,13,14, [...].
Can we create a temporary sequence and use the same logic as in T-SQL?
I tried to create a temp array of integers as a temp sequence, it works, but since the ids in the table is going up to 900,000 and more, I don't think it's the opti开发者_JAVA百科mal way to do this.
Given your table of integer values "strs" this should retrieve the missing integer values:
var missing = from i in Enumerable.Range(strs.Min(),strs.Max())
where !strs.Contains(i)
select i;
精彩评论