开发者

How to get block of unused ids in table with LTS?

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; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜