This is something that seems like we need to do often, and the execute code is a bit cumbersome so, what about something like this?
Public Module LLBLGenProQueryExtender
<System.Runtime.CompilerServices.Extension()> _
Public Function ToEntityCollection(Of t As EntityBase2)(ByVal q As IQueryable) As EntityCollection(Of t)
If Not TypeOf q Is ILLBLGenProQuery Then
Throw New ApplicationException("Only ILLBLGenProQuery may be outputed as EntityCollections")
End If
Return CType(q, ILLBLGenProQuery).Execute(Of EntityCollection(Of t))()
End Function
End Module
so you can do this:
Dim meta = New metadata(New dataadapter)
Dim q = From d In meta.Document Where _
d.PartId.Equals(part.PartId) OrElse _
(d.CompanyId.Equals(part.CompanyId) AndAlso d.PartId.HasValue) _
Select d
If prefetchDocumentGroups Then
q = q.WithPath(New PathEdge(Of DocumentGroupEntity)(DocumentEntity.PrefetchPathDocumentType))
End If
If prefetchDocumentTypes Then
q = q.WithPath(New PathEdge(Of DocumentTypeEntity)(DocumentEntity.PrefetchPathDocumentGroups))
End If
Return q.ToEntityCollection(Of PartEntity)()
I made it an extension of Iqueryable because i didn't want to cast each time i use it.
Also if you put this within a namespace that you import only when you are using llbl queries, then it will not appear on Iqueryables other places.