I have used the following code to get one more than the biggest ID in a table using razor
@foreach (var top in db.Query("SELECT MAX(ID)+1 as ID FROM mytable"))
{
if (@top.ID == null) {@top.ID = 1; }
}
if the table is empty, @top.ID returns null. I am trying to set its value to 1 if it is null. It however shows an error in the assignment part. How do you assign the value of @top.ID to something else? Or is there a way to user the sql query to set ID as 1 if the table is empty?