title: Construct queries in LINQ-to-Entities in Entity Framework ASP.NET MVC
body: <p>I'm having a hard time creating LINQ-to-Entities query that would fulfill my requirement.</p>
  
  <p>I have two tables: <strong>Booking</strong> and <strong>ProcessStatusLog</strong></p>
  
  <p><strong>Booking Table:</strong></p>
  
  <ul>
  <li>PNNumber (PK)</li>
  <li>AccountName</li>
  </ul>
  
  <p><strong>ProcessStatusLog Table:</strong></p>
  
  <ul>
  <li>ID (PK)</li>
  <li>PNNumber (FK)</li>
  <li>InsuranceCode</li>
  <li>Status</li>
  <li>UpdatedOn</li>
  </ul>
  
  <p>Here is the sample data for these tables:</p>
  
  <p>Booking Table</p>
  
  <pre><code>|----------|----------------|
  | PNNumber | Account Name   |
  |----------|----------------|
  | 11111    | Boston Celtics |
  |----------|----------------|
  | 22222    | Miami Heat     |
  |----------|----------------|
  </code></pre>
  
  <p>ProcessStatusLog Table</p>
  
  <pre><code>|------|-----------|---------------|--------------|-------------|
  | ID   | PNNumber  | InsuranceCode | Status       | UpdatedOn   |
  |------|-----------|---------------|--------------|-------------|
  | 1    | 11111     | FIRE          | NEW          | 02/22/2020  |
  |------|-----------|---------------|--------------|-------------|
  | 2    | 11111     | FIRE          | FOR REVIEW   | 02/23/2020  |
  |------|-----------|---------------|--------------|-------------|
  | 3    | 22222     | FIRE          | NEW          | 02/24/2020  |
  |------|-----------|---------------|--------------|-------------|
  | 4    | 22222     | MORTGAGE      | NEW          | 02/25/2020  |
  |------|-----------|---------------|--------------|-------------|
  | 5    | 22222     | MORTGAGE      | FOR REVIEW   | 02/26/2020  |
  |------|-----------|---------------|--------------|-------------|
  | 6    | 22222     | FIRE          | CANCELLED    | 02/28/2020  |
  |------|-----------|---------------|--------------|-------------|
  </code></pre>
  
  <p>Now, I want to get the latest status for a single PN per Insurance Code.</p>
  
  <p>For example:
  I want to get the latest status for PNNumber 11111. The output that I want to get is <strong>"FOR REVIEW".</strong></p>
  
  <p>And for PNNumber 22222, the required output would be <strong>"FOR REVIEW, CANCELLED"</strong></p>
  
  <p>How can I write the EF query for this?
  Thanks.</p>