title: Server-side validation of a REQUIRED String Property in MVC2 Entity Framework 4 does not work
body: <p>I'm trying to get server-side validation of an Entity Framework String Property to work. Other server-side validation such as data type validation and required dateTime and numeric EF properties are working. </p>
  
  <p>This in VS 2010, .Net 4.0, MVC2 + Cloud, ADO.Net Entity Framework.</p>
  
  <p>The String Property I am having issues with is mapped to a SQL 2008, Varchar(50) non-nullable column.</p>
  
  <p>When I try to post to my Create action with an empty string for this Property, I get the follwing error. </p>
  
  <blockquote>
    <p>Exception Details: System.Data.ConstraintException: This property cannot be set to a null value.</p>
  </blockquote>
  
  <p>When I post to the action with a blank space, I successfully get a required field validation message. </p>
  
  <p>I have tried using Data Annotations and ClientSideValidation but there seems to be issues with ClientSideValidation working on partial views and jquery dialogs.</p>
  
  <p>Here is the orginal autogenerated code from the entity framework.</p>
  
  <pre><code>[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
  [DataMemberAttribute()]
  public global::System.String GradeTypeName
  {
      get
      {
          return GradeTypeName;
      }
      set
      {
          OnGradeTypeNameChanging(value);
          ReportPropertyChanging("GradeTypeName");
          _GradeTypeName = StructuralObject.SetValidValue(value, false);
          ReportPropertyChanged("GradeTypeName");
          OnGradeTypeNameChanged();
      }
  }
  </code></pre>
  
  <p>Depending on the signature of the Action method (CREATE or EDIT), the exception can occur before stepping into the method or within the method when UpdateModel() is called. The inner exception is at the line below from the model.designer.cs file. </p>
  
  <pre><code>_GradeTypeName = StructuralObject.SetValidValue(value, false);
  </code></pre>
  
  <p>I have been able to reproduce this on a simple mvc2 web application.</p>