It is sometimes necessary to convert a generic entity collection to a general entityCollection and vice versa. The utility functions I wrote to this are as follows. I wanted to make sure this is the best way to do this:
to convert generic entityCollection to the general one
Public Function GenericEntityCollectionAsEntityCollection(Of TEntity As EntityBase2)( _
ByVal collectionToConvert As EntityCollection(Of TEntity)) As EntityCollection
Dim toReturn As EntityCollection = Nothing
If collectionToConvert IsNot Nothing Then
toReturn = New EntityCollection(collectionToConvert.EntityFactoryToUse)
End If
For Each ent As TEntity In collectionToConvert
toReturn.Add(ent)
Next
Return toReturn
End Function
to convert a general entityCollection to the generic one
Public Function EntityCollectionAsGenericEntityCollection(Of TEntity As EntityBase2)( _
ByVal collectionToConvert As EntityCollection) As EntityCollection(Of TEntity)
Dim toReturn As EntityCollection(Of TEntity) = Nothing
If collectionToConvert IsNot Nothing Then
toReturn = New EntityCollection(Of TEntity)(collectionToConvert.EntityFactoryToUse)
End If
For Each ent As TEntity In collectionToConvert
toReturn.Add(ent)
Next
Return toReturn
End Function