title: Annotation for an integer field - EF 4, MVC 4?
body: <p>I have this table:</p>
  
  <pre><code>[Table("MyTable", Schema = "MySchema")]
  public class MyTable
  {
      [Key, Column(Order = 0)]
      [Required(AllowEmptyStrings = false
      public string LanguageID { get; set; }
  
      [Key, Column(Order = 1)]
      [Required(AllowEmptyStrings = false
      public byte YearID { get; set; }
  
      [Key, Column(Order = 2)]
      [Required(AllowEmptyStrings = false)]
      public byte SIMSCodeID { get; set; }
  
      [Required(AllowEmptyStrings = true)]
      public string Data { get; set; }
  
      [Required(AllowEmptyStrings = true)]
      public int UserID { get; set; }
  
      [Required(AllowEmptyStrings = true)]
      public int brformula { get; set; }
  }
  </code></pre>
  
  <p>As you can see the last two fields are integers. What should be annotation for those so that I don't get this error when trying to access a row in this table with AJAX:</p>
  
  <p>Message:</p>
  
  <pre><code>The 'brformula' property on 'MyTable' could not be set to a 'null' value. You must set this property to a non-null value of type 'Int32'. 
  </code></pre>
  
  <p>Exception type:</p>
  
  <pre><code>System.Data.ConstraintException
  </code></pre>
  
  <p>Code line where the error happens:</p>
  
  <pre><code>MyTable myTable= db.MyTableDbSet.Find(langid, year, simscodeid);
  </code></pre>
  
  <p>Api controller method:</p>
  
  <pre><code>[HttpGet]
  public HttpResponseMessage GetSIMSData(string langid, byte year, byte simscodeid)
  {
      try
      {
          MyTable myTable = db.MyTableDbSet.Find(langid, year, simscodeid);
  
          if (MyTable == null)
          {
              return Request.CreateResponse(HttpStatusCode.OK, this.getSimsDataObject(false, myTable));
          }
          else
          {
              return Request.CreateResponse(HttpStatusCode.OK, this.getSimsDataObject(true, myTable));
          }
      }
      catch (Exception e)
      {
          return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
      }
  }
  </code></pre>
  
  <p>My AJAX call:</p>
  
  <pre><code>    getSIMSDataByAllParams: function (langId, year, simscodeid) {
          jq.ajax({
              contentType: 'application/json; charset=utf-8',
              type: "GET",
              url: "/api/MyTable",
  
              data: {
                  langid: langId,
                  year: year,
                  simscodeid: simscodeid,
                  brformula: 0
              },
  
              dataType: "json",
  
              beforeSend: function (jqXHR, settings) {
                  simsDataView.resetStatusAndErrorTf();
                  simsDataView.setStatusMsg(simsDataView.getMessageByLang(langId, 'fetchingTreeNodeDataMsg'), constants.TEXT_COLOR_BLUE);
              },
  
              success: function (data, textStatus, jqXHR) {
                  simsDataByAllParams = {};
                  simsDataByAllParams = JSON.parse(data);
              },
  
              complete: function (jqXHR, textStatus) {
                  if (simsDataByAllParams.hasData) {
                      tinymce.activeEditor.setContent(simsDataByAllParams.simsDataObject.Data);
                  } else {
                      tinymce.activeEditor.setContent(simsDataView.getMessageByLang(langId, 'addEditorContentMsg'));
                  }
  
                  dbDirty = false;
                  simsDataView.setStatusMsg(simsDataView.getMessageByLang(langId, 'treeNodeDataFetchedMsg'), constants.TEXT_COLOR_GREEN);
              },
  
              error: function (jqXHR, textStatus, errorThrown) {
                  errorsMsgTxt.append(simsUtility.printAjaxError(langId, jqXHR, textStatus, errorThrown));
              }
          });
      },
  </code></pre>
  
  <p>Note: Currently, the field in DB allows nulls, but I want it to be default value of 0.
  Why it doesn't complain about UserID? It too is integer and allows nulls.</p>