ToString1
asked on
linq to sql - how to get next highest id in query
In linq say my query returns the first and last foo object
FOO first = dataContext.Foos.First();
FOO last = dataContext.FOOs.Last();
Great! The FOO table has an autoincrement number which works great.
Now I want to be able to get the next FOO object with the next highest ID, so my query would be something like
FOO nextFoo = dataContext.FOOs //get the next foo object
So my question is how to get the next FOO object with the next highest ID?
FOO first = dataContext.Foos.First();
FOO last = dataContext.FOOs.Last();
Great! The FOO table has an autoincrement number which works great.
Now I want to be able to get the next FOO object with the next highest ID, so my query would be something like
FOO nextFoo = dataContext.FOOs //get the next foo object
So my question is how to get the next FOO object with the next highest ID?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Even better, this.
// The ID used to get the next ID in the database table
int id = 5;
FOO last = dataContext.FOOs.Where(f => f.ID > id).Take(1);
ASKER
Each time I want to call the next foo.ID
No they have all been created and also the ID is autoincrement in database