Tuesday, September 24, 2013

LINQ - Get First Unused ID

I just spent two hours pounding my head against the proverbial wall trying to get some Logofrag stuff to work correctly.  After messing around with all manner of methods, I found an amazing StackOverflow answer that put all the pieces in place.  This is how I finally was able to find the first unused permission ID:

Dim idsQuery = From right In data.ThreadRights Select right.RightID

Return (From n In idsQuery Where (Not idList.Select(Function(x) x).Contains(n + 1)) Order By n Select n + 1).First

I had never before used lambdas, so that's another thing I learned.  They're very easy, just say whether it's a function or sub, give the arguments it takes, and write the return value.

No comments:

Post a Comment