I’m working on a project that contains 5 tables:
This–>ThisThat<–That–>ThatFoo<–Foo
I’ve defined the table relationships through models in the asp.net Entity Framework:
‘This’ contains columns: ThisID(PK), Name.
‘ThisThat’ contains columns: ThisThatID(PK), ThisID(FK), ThatID(FK).
‘That’ contains columns: ThatID(PK), Name.
‘ThatFoo’ contains columns: ThatFooID(PK), ThatID(FK), FooID(FK).
Ok, so I have ‘FooID’ and I need to get a list of related ‘ThisThat’.
Here’s what I’ve tried:
int FooID = 1;
IEnumerable<int> thatIDs = db.ThatFoo.Where(tf=>tf.FooID == FooID).ToList();
IEnumerable<ThisThat> thisthats = db.ThisThat.Where(tt=>tt.ThatID == thatIDs).ToList();
And:
IEnumerable<ThisThat> thisthat = db.ThisThat.Include(p=>p.That.ThatFoo.Where(x=>x.FooID == FooID)).ToList();
I’ve also played around with .Select and .SelectMany. I’ve google searched all kinds of things but I’m not finding anything that relates to my situation.
I’m not really sure what else to try…suggestions (please & thanks for reading)?
Try