I’ve mapped my classes with default EF way, and all my FKs are EntityCollection, so for example Bike.Wheels would be EntityCollection.
How do I work with Wheels?
- I want to retrieve 1st and 2nd wheel
- I want to loop through Wheels
- I want to get all wheel.Bolts
I could not use get/select/[].
Am I missing something?
Well, some operations are really simple – others are a bit kludgy – so you might want to redesign some of your approaches to use the easy methods.
To loop over all your wheels, just use a
foreachstatement:Getting the first, second etc. of a collection is a bit more tricky, since you cannot use the usual array indexing. You can:
.Skip()method – but that’s a bit clumsy for single object retrievalList<T>and then use array indexingSo either you use something like this:
or you materialize the collection into a list: