Entity Framework Count Child Entities

Expanding on the post “Entity Framework Filter Child Entity“, I finally figured out how to get a GridView to show the count of child records. Unfortunately I am returning the whole set of entities and doing a Count on them. It’s not a problem in this case. I’m just happy it works.

Dim query = (From x In db.OrderChecklistItems Where x.Enabled = True Order By x.Enabled Descending, x.ItemText Select OCI = x, _
            
OD = From y In x.OrderDocuments Where y.OrderID = OrderID, _
            
CS = From z In x.OrderChecklistSelections)
 
Dim customers = From item In query.ToList Select item.OCI
 
GridView1.DataSource = customers
GridView1.DataBind()

Then in the GridView:

Eval("OrderChecklistSelections.Count")