bchebrou wrote:
Hello,
Is it possible to get the EntityType (Public Enum EntityType As Integer) of an Entity at runtime ?
I didn't undertand what you want to get... do you want an instance of a Type object representing the EntityType enumeration?
You can get this object having a reference to the assembly containing this type.
bchebrou wrote:
My goal is to expose a service (remoting) which make it possible to the users to get an EntityCollection and all related entities, only with the type of the first entity.
public IEntityCollection2 GetEntityCollection(Type entityType)
{
// Create an EntityCollection with the IEntityFactory2 of the entity :
// Get with reflection and CreateEntityFactory()...
// Create a prefetchPath : here i need to get the value of the EntityType
// Add dynamically PrefetchPathElement (reflection ?)
// Fetch and return the Collection
}
I need to do this because i've a lot of settings table. I think is not to hard to generate at runtime controls in a winform to modify or create entity. But before i need to find a generic way to get all the data.
Do you think, this is possible ?
Cheers,
Benjamin
To create at runtime a typed entitycollection you can do the followyng
dim pEntityType As Type
Dim genericType As Type
genericType = GetType(EntityCollection(Of )) 'Get a Type representing the generic EntityCollection
Dim boundType As Type
boundType = genericType.MakeGenericType(pEntityType) 'Create the Type representing the typed EntityCollection(Of pEntityType)
dim myEntityColl as IEntityCollection2
myEntityColl = system.Activator.CreateInstance(boundType) 'get an instance of the typedEntityCollection
This is VB, but I hope you get the idea...