title: Entity framework required field does not accept space
body: <p>I have a simple SQL Server table:</p>
  
  <pre><code>CREATE TABLE [dbo].[Table3]
  (
      [PK] [int] NOT NULL DEFAULT ((0)),
      [field1] [varchar](50) NOT NULL DEFAULT (' '),
      [field2] [varchar](1) NOT NULL DEFAULT (' '), 
  
      CONSTRAINT [Table3_PrimaryKey] PRIMARY KEY CLUSTERED([PK] ASC) ON [PRIMARY]
  ) ON [PRIMARY] 
  </code></pre>
  
  <p>In SQL Server, the following queries are valid:</p>
  
  <pre><code>   INSERT INTO Table3
     VALUES (1, 'Test1', ' ')
  
     INSERT INTO Table3
     VALUES (2, 'Test2', '')
  
     INSERT INTO Table3 (PK, field1)
     VALUES (3, 'Test3')
  
     INSERT INTO Table3
     VALUES (4, 'Test4', 'X')
  </code></pre>
  
  <p>I have created a console application with Entity Framework 6 code first. When I try to add a new record, the insert fails with "Required field" error. It seems a space is not valid for field2, but in SQL it's legal.</p>
  
  <pre><code>using System.Text;
  using System.Threading.Tasks;
  
  namespace ConsoleApplication2
  {
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
              using (Model1 ctx = new Model1())
              {
                  ctx.Database.Log = Console.WriteLine;
                  Table3 t3 = new Table3();
                  t3.PK = 1;
                  t3.field1 = "Test";
                  t3.field2 = " ";
                  ctx.Table3.Add(t3);
                  ctx.SaveChanges();
              }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                Console.Write(ex.Message);
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
    }
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>namespace ConsoleApplication2
  {
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
  
    public partial class Model1 : DbContext
    {
      public Model1()
          : base("name=Model11")
      {
      }
  
      public virtual DbSet&lt;Table3&gt; Table3 { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Table3&gt;()
              .Property(e =&gt; e.field1)
              .IsUnicode(false);
  
          modelBuilder.Entity&lt;Table3&gt;()
              .Property(e =&gt; e.field2)
              .IsUnicode(false);
      }
    }
  }
  </code></pre>
  
  <p>Table</p>
  
  <pre><code>namespace ConsoleApplication2
  {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Data.Entity.Spatial;
  
    public partial class Table3
    {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.None)]
      public int PK { get; set; }
  
      [Required]
      [StringLength(50)]
      public string field1 { get; set; }
  
      [Required]
      [StringLength(1)]
      public string field2 { get; set; }
    }
  }
  </code></pre>
  
  <p>Thanks
  Michele</p>