title: How can I get the Max id of a table or 1 if empty using Linq?
body: <p>i manually insert the id of a table by selecting the max id from the table and increment it by 1. how do i do that with c# and linq if the table is empty and the max returns null i'm using the below code but it is giving the error "The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type"</p>
  
  <pre><code>var t = (from tab1 in db.questions select tab1.QuestionId1).Max();
              if (t!=null)
              {
                   qui = t + 1;
              }
  
              else
              {
                   qui = 1;
              }
  </code></pre>