For Adapter, I use this code:
Public Shared Function CreateNewTypedEntityCollection(ByVal DbGenericAssemblyReference As System.Reflection.Assembly, ByVal EntityName As String) As IEntityCollection2
'get entity full name
Dim fullEntityTypeName As String
fullEntityTypeName = DbGenericAssemblyReference.FullName.Substring(0, DbGenericAssemblyReference.FullName.IndexOf(","c)) & ".EntityClasses." & EntityName
'get entity Type
Dim entityType As Type
entityType = DbGenericAssemblyReference.GetType(fullEntityTypeName, False, True)
'get name of GENERIC entity collection
Dim UNboundGenericEntityCollectionTypeName As String
UNboundGenericEntityCollectionTypeName = DbGenericAssemblyReference.FullName.Substring(0, DbGenericAssemblyReference.FullName.IndexOf(","c)) & ".HelperClasses.EntityCollection`1"
'get UNBOUND type of GENERIC entity collection
Dim UNboundGenericEntityCollectionType As Type
UNboundGenericEntityCollectionType = DbGenericAssemblyReference.GetType(UNboundGenericEntityCollectionTypeName, True, True)
'create typed (BOUND) type of the entityCollection
Dim BOUNDgenericEntityCollectionType As Type
BOUNDgenericEntityCollectionType = UNboundGenericEntityCollectionType.MakeGenericType(entityType)
'create the instance in the typed EntityCollection
Dim ec As IEntityCollection2
ec = DirectCast(System.Activator.CreateInstance(BOUNDgenericEntityCollectionType), IEntityCollection2)
Return ec
End Function
this will give you a new instance of a typed entity collection. The entity collection will be "typed" on the entity specified.
The simplest way to obtain a reference to the DbGeneric assembly is to put somewhere in a class of the DB generic assembly the following code
Public Shared Function GetAssemblyRef() As System.Reflection.Assembly
Return System.Reflection.Assembly.GetExecutingAssembly
End Function
If this code is in the DB Generic assembly, it will return a reference to the current instance of the DB Generic assembly.