I have a One-Many relation with two Entities :
Order:
int OrderId
string OrderNumber
...
OrderItem:
int ItemId
int sequence
decimal Quantity
...
One Order Has multiple OrderItems, I want to write a Linq that return all orders with their items and items be sorted by sequence field.
How can i write a query such as following query?
Order myOrder = db.Orders.Include("OrderItems").Include("sequence").FirstOrDefault(x => x.OrderId == 3);
You can’t do that without projecting the results into a new type.
Whilst it’s not ideal projecting it into a new object, according to this blog post, there is a nice side-effect that now
order.OrderItemson your anonymous object will be sorted correctly too.