title: System.NotSupportedException: Member Month of type System.DateTimeOffset in the expression tree {ExampleModel}{EndTime}.Month cannot be translated
body: <p>I'm trying to do this method:</p>
  <pre><code>Task&lt;Result&lt;IQueryable&lt;ExampleViewModel&gt;&gt;&gt; Handle(ExampleQuery request) 
  {
     return Result.Success(_repository.Get()
                          .SelectMany(x =&gt; x.ExampleModel)
                          .Select(y =&gt; new ExampleViewModel(
                                      y.EndTime.Month,
                                      y.EndTime,
                                      y.IsOK,
                                      y.Name)));
  }
  </code></pre>
  <p>but this generated the error bellow:</p>
  <blockquote>
  <p>System.NotSupportedException: Member Month of type
  System.DateTimeOffset in the expression tree
  {ExampleModel}{EndTime}.Month cannot be translated. The unsupported
  member type is located on type 'ViewModels.ExampleViewModel'. Path: $.
  ---&gt; System.NotSupportedException: Member Month of type System.DateTimeOffset in the expression tree
  {ExampleModel}{EndTime}.Month cannot be translated.</p>
  </blockquote>
  <p>but if I break the code creating a list before:</p>
  <pre><code>Task&lt;Result&lt;IQueryable&lt;ExampleViewModel&gt;&gt;&gt; Handle(ExampleQuery request)
    {
        var listModel = _repository.Get()
                      .SelectMany(x =&gt; x.ExampleModel).ToList();
      
        return Result.Success(listModel
                 .Select(y =&gt; new ExampleViewModel(
                     y.EndTime.Month,
                     y.EndTime,
                     y.IsOK,
                     y.Name)).AsQueryable());
    } 
  </code></pre>
  <p>and the error disappears. Everything works fine:</p>
  <pre><code>[
    {
      &quot;month&quot;: 3,
      &quot;date&quot;: &quot;2022-03-30T15:59:14.6422341-03:00&quot;,
      &quot;IsOK&quot;: false,
      &quot;Name&quot;: &quot;example name&quot;
    }
  ]
  </code></pre>
  <p>my Model:</p>
  <pre><code>    public class ExampleModel
      {
          public ExampleModel(string name, bool isOK, DateTimeOffset startTime, DateTimeOffset endTime)
          {
              Name = name;
              IsOK = isOK;
              StartTime = startTime;
              EndTime = endTime;
          }
  
          public string Name { get; protected set; }
          public bool IsOK{ get; protected set; }
          public DateTimeOffset StartTime { get; protected set; }
          public DateTimeOffset EndTime { get; protected set; }
      }
  </code></pre>
  <p>my ViewModel</p>
  <pre><code>public class ExampleViewModel
  {
      public ExampleViewModel(int month, DateTimeOffset date, bool isOK, string name)
      {
          Month = month;
          Date = date;
          IsOK = isOK;
          Name = name;
      }
  
      public int Month { get; set; }
      public DateTimeOffset Date { get; set; }
      public bool IsOK { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  <p>this is how the collection looks like (I'm not the creator and don't have permission to change any)</p>
  <pre><code>{  
      &quot;_id&quot;: &quot;6244a72f902597a15d941b04&quot;,  
      &quot;_t&quot;: &quot;Examples&quot;,  
      &quot;CreatedAt&quot;: [    
          {      
              &quot;$numberLong&quot;: &quot;637842632155392881&quot;    
          },    
          0  ],  
      &quot;Example&quot;: [    
      {
          &quot;Name&quot;: &quot;example name&quot;,      
          &quot;IsOK&quot;: false,      
          &quot;StartTime&quot;: [        
          {          
              &quot;$numberLong&quot;: &quot;637842526150485990&quot;        
          },        
          -180      ],      
          &quot;EndTime&quot;: [        
          {          
              &quot;$numberLong&quot;: &quot;637842527546422341&quot;        
          },        
          -180      ]    
      }
  ]
  </code></pre>
  <p>I guess it's a problem with MongoDB.Driver, but maybe there is a way to run this without use a list.</p>
  <p><strong>[Edit]</strong></p>
  <p>after thinking a little more, this was my solution:</p>
  <p>I removed the month from my Viewmodel constructor:</p>
  <pre><code>Task&lt;Result&lt;IQueryable&lt;ExampleViewModel&gt;&gt;&gt; Handle(ExampleQuery request)
  {
     return Result.Success(_repository.Get()
                              .SelectMany(x =&gt; x.ExampleModel)
                               .Select(y =&gt; new ExampleViewModel(
                                            y.EndTime,
                                            y.Passed,
                                            y.Name)));
  }
  </code></pre>
  <p>and now the class have all the control over the property:</p>
  <pre><code>public ExampleViewModel(DateTimeOffset date, bool passed, string name)
  {
      Date = date;
      IsOK = isOK;
      Name = name;
  }
  
  public int Month
  {
      get { return Date.Month; }
  }
  
  public DateTimeOffset Date { get; private set; }
  public bool IsOK { get; private set; }
  public string Name { get; private set; }
  </code></pre>