title: Entity SQL Datetime Syntax error
body: <p>Anyone know What is wrong with my syntax here? I am making dynamic eSQL Queries and running into an error when trying to make where condition for DateTime data type. This is the error:</p>
  
  <p>The query syntax is not valid. Near term '2011', line 1, column 135.</p>
  
  <p>If it matters the DateTime type in my entity is actually nullable DateTime? </p>
  
  <p>However, I thought this is the correct syntax from everything I've read. </p>
  
  <p>Here is the code: </p>
  
  <pre><code>List&lt;EntityFilter&lt;FirstRead&gt;&gt; filters = new List&lt;EntityFilter&lt;FirstRead&gt;&gt;()
          {
              new EntityFilter&lt;StudyFirstRead&gt; { PropertyName = "username", OpType = ExpressionType.Equal, Value = "cwoodhouse" },
              new EntityFilter&lt;StudyFirstRead&gt; { PropertyName = "FirstRead", OpType = ExpressionType.LessThan, Value = "DATETIME'2011-02-01 00:00'" }
          };
  </code></pre>
  
  <p>Where EntityFilter is:</p>
  
  <pre><code>  public class EntityFilter&lt;T&gt;
  {
      public string PropertyName { get; set; }
      public ExpressionType OpType { get; set; }
      public object Value { get; set; }
  </code></pre>
  
  <p>And I am building dynamic queries like so:</p>
  
  <pre><code>StringBuilder builder = new StringBuilder();
  
          int counter = 0;
  
          string baseStr = @"SELECT VALUE val FROM " + contextName + "." + tableName + " AS val WHERE val.";
  
          builder.Append(baseStr); 
  
          foreach (EntityFilter&lt;T&gt; filter in filters)
          {
              //builder.Append(filter.PropertyName + " " + filter.OpTypeString() + " @p" + counter);
              builder.Append(filter.PropertyName + " " + filter.OpTypeString() + "'" + filter.Value + "'"); 
              counter++;
  
              if (counter &lt; filters.Count)
                  builder.Append(" AND val."); 
              else
              {
                  break; 
              }
          }
  
          return builder.ToString(); 
  </code></pre>