views:

23

answers:

1

I am using the POCO support for entity framework v4. I would like to get the Type of the POCO class that is mapped to that entity. For example you can get ObjectStateEntry from the ObjectStateManager. That entry then has a reference to the entity. The Entity is of type object so it is useless until you cast it.

This is fine if you know what the type of the entity maybe at compile but what if you wanted it at runtime. Does the entity framework store anywhere the CLR type of that entity.

+2  A: 

Yes, you can do:

var mappedType = MyObjectContext.GetObjectType(myEntity.GetType());
Craig Stuntz