So far we’ve considered only navigation properties that return a single entity. Navigation properties can return many entities. The myOrder.OrderDetails navigation property, for example, returns the many line items of a single order.
Navigation properties that return multiple entities are sometimes termed parent->child or principal->dependent properties. In these cases, the property belongs to the parent entity such as Order and it returns child entities such as OrderDetail entities.
The navigation property returns child entities in a RelatedEntityList<T> collection. For example, the Order.OrderDetails property returns its OrderDetail children in a concrete collection, RelatedEntityList<OrderDetail>.
I write and run the following statements and learn that there are three line items in the collection owned by anOrder:
| C# | Order anOrder = _em1.Orders.FirstOrNullEntity(); RelatedEntityList<OrderDetail> lineItems = anOrder.OrderDetails; |
| VB | Dim anOrder As Order = _em1.Orders.FirstOrNullEntity() Dim lineItems As RelatedEntityList(Of OrderDetail)=anOrder.OrderDetails |
We decide to increase the quantity ordered for the first OrderDetail as follows.
| C# | var firstItem = lineItems[0]; firstItem.Quantity = 10; |
| VB | Dim firstItem As OrderDetail = lineItems(0) firstItem.Quantity = 10 |