title: How to get first day of month/year etc?
body: <p>I'm using <code>Linq.Dynamic</code> to query a <code>SQL Server</code> database.</p>
  
  <p>I have a date field named 'EnteredOn' which I need to convert to first second of that month (or year, minute etc)</p>
  
  <p>I tried basically everything, but everything throws an error</p>
  
  <p>Here are some of my trials</p>
  
  <pre><code>Return $"DateTime({FieldName}.Year,1,1)"
  Return $"DateTime({FieldName}.Year,{FieldName}.Month,1)"
  Return $"DateTime({FieldName}.Year,{FieldName}.Month,{FieldName}.Day)"
  Return $"DateAndTime.DateDiff(2, 0, {FieldName})"
  Return $"EntityFunctions.CreateDateTime({FieldName}.Year,{FieldName}.Month,{FieldName}.Day,0,0,0)"
  Return $"DbFunctions.CreateDateTime({FieldName}.Year,{FieldName}.Month,{FieldName}.Day,0,0,0)"
  </code></pre>
  
  <p>Either I get an error that I can only use parameterless constructors (so first 3 dont work), or that no such property or field exists (DateDiff), or it doesnt recognize the Class</p>
  
  <p>How can this be done?</p>
  
  <p>Some of the error messages</p>
  
  <blockquote>
    <p>No applicable method 'DateDiff' exists in type 'viwAttendancePre'<br>
    No property or field 'Microsoft' exists in type 'viwAttendancePre'<br>
    No property or field 'Month' exists in type 'viwAttendancePre'<br>
    LINQ to Entities does not recognize the method 'System.Nullable<code>1[System.DateTime] CreateDateTime(System.Nullable</code>1[System.Int32], System.Nullable<code>1[System.Int32], System.Nullable</code>1[System.Int32], System.Nullable<code>1[System.Int32], System.Nullable</code>1[System.Int32], System.Nullable`1[System.Double])' method, and this method cannot be translated into a store expression.<br>
    No applicable method 'CreateDateTime' exists in type 'EntityFunctions'<br>
    No property or field 'DbFunctions' exists in type 'viwAttendancePre'<br>
    Only parameterless constructors and initializers are supported in LINQ to Entities.<br>
    No applicable method 'Date' exists in type 'viwAttendancePre'</p>
  </blockquote>
  
  <p><strong>Environment</strong></p>
  
  <p>Linq Package</p>
  
  <pre><code> &lt;Reference Include="System.Linq.Dynamic, Version=1.0.6132.35681, Culture=neutral, processorArchitecture=MSIL"&gt;
  &lt;HintPath&gt;..\..\_packages\System.Linq.Dynamic.1.0.7\lib\net40\System.Linq.Dynamic.dll&lt;/HintPath&gt;
  &lt;Private&gt;True&lt;/Private&gt;
  &lt;/Reference&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong> -Using <code>System.Linq.Dynamic.Core</code></p>
  
  <p>I see know that if i don't use the fields in the query it does work as follows</p>
  
  <pre><code>Dim d = GetSystemContext()
  Dim goodq = d.Set(GetType(Attendance)).AsQueryable.Select("new (DateTime(2000,1,1) as mydate)")' this returns just fine
  Dim badq = d.Set(GetType(Attendance)).AsQueryable.Select("new (DateTime(AddedOn.Year,1,1) as mydate)")' this throws "System.NotSupportedException: 'Only parameterless constructors and initializers are supported in LINQ to Entities.'"
  </code></pre>