I'm having a hard time creating a LINQ-to-Entities query that would fulfill my requirement.
I have two tables: Booking
and ProcessStatusLog
.
Booking table:
- PNNumber (PK)
- AccountName
ProcessStatusLog table:
- ID (PK)
- PNNumber (FK)
- InsuranceCode
- Status
- UpdatedOn
Here is the sample data for these tables:
Booking table
| PNNumber | Account Name |
+----------+----------------+
| 11111 | Boston Celtics |
| 22222 | Miami Heat |
| 33333 | LA Lakers |
ProcessStatusLog table:
| ID | PNNumber | InsuranceCode | Status | UpdatedOn |
+------+-----------+---------------+--------------+-------------+
| 1 | 11111 | null | NEW | 02/22/2020 |
| 2 | 11111 | FIRE | FOR REVIEW | 02/23/2020 |
| 3 | 22222 | null | NEW | 02/24/2020 |
| 4 | 22222 | MORTGAGE | FOR REVIEW | 02/25/2020 |
| 5 | 22222 | MORTGAGE | CORRECTION | 02/26/2020 |
| 6 | 22222 | FIRE | FOR REVIEW | 02/27/2020 |
| 7 | 33333 | null | NEW | 02/28/2020 |
| 8 | 22222 | FIRE | APPROVED | 02/29/2020 |
Now, I want to get a list of bookings per latest status.
For example: if I want to filter the bookings where the latest status is "CORRECTION", I will get the booking with PNNumber 22222.
If searching for "FOR REVIEW", I will just get the booking with PNNumber 11111.
If searching for "NEW", I will just get the booking with PNNumber 33333.
How can I write the EF query for this?
Thanks.