title: C# LINQ: DbFunctions.TruncateTime throw error This function can only be invoked from LINQ to Entities
body: <p>here is my code. </p>
  
  <pre><code>    List&lt;NPSEntity&gt; Data = null; ;
      using (var db = new NPSDbContext())
      {
          Data = (from n in db.NPSDatas
                      orderby n.AddDate, n.CountryCode
                      where DbFunctions.TruncateTime(n.NPSDate) &gt;= StartDate.Date &amp;&amp; DbFunctions.TruncateTime(n.NPSDate) &lt;= EndDate
                      select n).ToList();
      }
  
      NPSData = Data.Select(n =&gt; new NPSEntity
      {
          NPSDate = DbFunctions.TruncateTime(n.NPSDate),
          NPSAmount = n.NPSAmount,
          AddDate = n.AddDate,
          ModDate = n.ModDate,
          UserID = n.UserID,
          CountryCode = n.CountryCode
      }).ToList();
  
      if (NPSData!=null)
      {
          CountryCodes = NPSData.Select(e =&gt; e.CountryCode).Distinct();
          CountryCount = CountryCodes.Count();
      }
  </code></pre>
  
  <p>this line throwing error <code>NPSDate = DbFunctions.TruncateTime(n.NPSDate),</code> <strong>This function can only be invoked from LINQ to Entities</strong></p>
  
  <p>my objective is to remove time portion from <strong>NPSDate</strong>  <code>NPSDate = DbFunctions.TruncateTime(n.NPSDate)</code> that is why i used <code>DbFunctions.TruncateTime</code> function.</p>
  
  <p>tell me how could i fix this problem or tell me how could i remove time portion from NPSDate when fetching data from db. my NPSDate property look like <code>public DateTime? NPSDate { get; set; }</code> that is why i can not use <code>NPSDate.Date</code></p>
  
  <p>please guide me. thanks</p>