In a project I'm working on, I have four entities(amongst a bunch of others), WorkOrder, Crew, CrewAssignment, and Contractor. Their relationship is like this:
- A WorkOrder has one Contractor, which can be changed
- A Crew only ever has one Contractor
- A CrewAssignment only ever has one Crew
- A WorkOrder has many CrewAssignments
The problem I'm having is setting up the last part where a WorkOrder can have multiple CrewAssignments. What I want to do is ensure that the WorkOrder.CrewAssignments property only returns the CrewAssignments that have a Crew with the same Contractor as the WorkOrder. Or, less wordy, "where WorkOrder.Contractor == CrewAssignment.Crew.Contractor".
The only thing I've been able to come up with is this, but it throws an exception about the x variable being undefined.
HasMany(x => x.CrewAssignments).KeyColumn("WorkOrderID").Where(x => x.Crew.Contractor == x.WorkOrder.Contractor);
Is doing something like this even possible? Or am I barking up the wrong tree entirely? Google's been failing me all morning with this one. Any ideas?