title: Get TimeSpan property in EF projection for TimeSpan converted from ticks
body: <p>I'm following the advice from here:</p>
  
  <p><a href="https://stackoverflow.com/questions/8503825/what-is-the-correct-sql-type-to-store-a-net-timespan-with-values-240000">What is the correct SQL type to store a .Net Timespan with values &gt; 24:00:00?</a></p>
  
  <p>Inside a model named TimesheetEntry I have:</p>
  
  <pre><code>public Int64 NetLengthTicks { get; set; }
  
  [NotMapped]
  public TimeSpan NetLength
  {
      get { return TimeSpan.FromTicks(NetLengthTicks); }
      set { NetLengthTicks = value.Ticks; }
  }
  </code></pre>
  
  <p>I'm attempting this:</p>
  
  <pre><code>var shiftsData = from shift in filteredShifts
                  where shift.IsDeleted == false
                  select new
                  {
                      shift.TimesheetShiftId,
                      shift.UserId,
                      shift.HasShiftEnded,
                      shift.StartTime,
                      shift.EndTime,
                      Entries = from entry in shift.Entries
                              where entry.IsDeleted == false
                              select new
                              {
                                  entry.TimesheetEntryId,
                                  entry.TimesheetShiftId,
                                  entry.EntryType,
                                  entry.StartTimeSpan,
                                  entry.NetLength,
                              }
                  };
  </code></pre>
  
  <p>I get the exception:</p>
  
  <pre><code>The specified type member 'NetLength' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
  </code></pre>
  
  <p>I tried to change the projection to:</p>
  
  <pre><code>NetLength = TimeSpan.FromTicks(entry.NetLengthTicks)
  </code></pre>
  
  <p>but that gave the exception:</p>
  
  <pre><code>LINQ to Entities does not recognize the method 'System.TimeSpan FromTicks(Int64)' method, and this method cannot be translated into a store expression.
  </code></pre>
  
  <p>I then tried creating an expression to do the conversion:</p>
  
  <pre><code>public static Expression&lt;Func&lt;DAL.Models.TimesheetEntry, TimeSpan&gt;&gt; NetLengthExpression
  {
      get
      {
          return e =&gt; TimeSpan.FromTicks(e.NetLengthTicks);
      }
  }
  
  // in the projection
  NetLength = NetLengthExpression
  </code></pre>
  
  <p>But that threw:</p>
  
  <pre><code>The LINQ expression node type 'Lambda' is not supported in LINQ to Entities.
  </code></pre>
  
  <p>Is there a way to expose NetLength as a TimeSpan to be returned in my query?</p>