I am using Linq to Sql against a SQL Server Compact database.
I need a fast way to find the first hole in an integer based column or if none exist the highest number + 1.
If I was doing it using SQL I would do something like this:
SELECT IdLegacy+1 FROM FLUID AS t1
LEFT JOIN FLUID as t2
ON t1.IdLegacy = t2.IdLegacy+1
WHERE t2.IdLegacy IS NULL
Basically I need something similar in Linq to Sql to achieve the same thing. As it will be called on every insert, I need it to be fast and preferable elegant :-D.
Thanks
A left outer join looks like this in LINQ to SQL
maybeGapnow reflects a record that’s aleft outer joinfrom fluid. It might be that the LINQ provider for SQL Compact is limited as SQL Compact is very limited but this is the nuts and bolt of it.You can test it using this little test case:
Prints
4and6, just ignore the last as it will always be there and there’s no easy way to prevent that from occurring without using window functions which aren’t supported by SQL Compact.