One type of entity in my model (let's call it E1) needs to be able to treat its relationship with another entity type (E2) as a stack. Reciprocally, that other entity needs to be able to see all related entities of the first type where the E2 is at the top of the stack, and separately every case where the E2 is within a stack for an E1.
That doesn't sound all that clear to me, so let me try and demonstrate:
E1 entities: foo { stack: quux, plugh, glurp }, bar { stack: plugh, glurp }, baz { stack: quux, plugh }
E2 entities: quux { top: null
; in: foo, baz }, plugh { top: baz; in: foo, bar, baz }, glurp { top: bar; in: foo, bar }
Right now, I have a database table which has columns for the keys to both E1 and E2, as well as an int for storing the E2's position in the stack. Entity Framework treats this table as its own entity, rather than part of the relationship between E1 and E2, which complicates queries and just leads to some plain ugly code.
I know I'm doing it wrong, but is it possible to do this right? And if so, how?