title: How can i access an object in a list in c# query with ef?
body: <p>So I´m having a problem with a query im trying to do. I´m trying to get the last element of a list in a linq query in c# using ef.</p>
  <p>Here is the code im trying to execute:</p>
  <pre><code> public List&lt;Viagem&gt; getViagensToBeCompletedInBlocoTrabalho()
   {
       return this.context.Viagens
          .Where(v =&gt; v.blocosTrabalho.Count() == 0
            || !v.blocosTrabalho.LastOrDefault().noFim.Equals(v.horasPassagem.LastOrDefault().codigoNo)
          )
          .ToList();
   }
  </code></pre>
  <p>But i get this error: Queries performing 'LastOrDefault' operation must have a deterministic sort order. Rewrite the query to apply an 'OrderBy' clause on the sequence before calling 'LastOrDefault'.</p>
  <p>What am i doing wrong here?</p>
  <p>By the way the sorting that i want is the order of entries in the table so i don´t really want to sort anything. Although i have also tested sorting and it doesn´t work.</p>
  <p>Thanks for the help in advance :-)</p>