Entity Framework Filter Child Entity

I was looking for a way to filter child entities with eager loading. I ran into this useful blog post by Beth Massi on the subject.

Here is the code I ended up using. It doesn’t work with server-side paging, but I didn’t need it in this case.

Dim query = (From x In db.OrderChecklistItems Where x.Enabled = True Select OCI = x, _
OD = From y In x.OrderDocuments Where y.OrderID = OrderID)

Dim customers = From item In query.ToList Select item.OCI

GridView1.DataSource = customers