Dynamic proxies have names like ClassName_00394CF1F92740F13E3EDBE858B6D599DFAF87AA5A089245977F61A32C75AA22
where the POCO class was simply called Classname
.
I know to can get the POCO type of an EF dynamic proxy instance with ObjectContext.GetObjectType(instance.GetType())
, but is there an easier way to get the proxy type of a given EF class than this:
databaseContext.TableName.First().GetType();
As this requires there be an instance of the type in the table (usually the case, but this smells "wrong").
I am passing class types to a function (like below) so that certain parent/child drag & drop rules can be applied to TreeNodes (the object instances are referenced by Tag property of TreeNodes so have the dynamic type for any EF objects).
if (!AllowChildDrop(e.Node, e.TargetNode, e.DropPosition, typeof(Answer)), typeof(Question)))
So basically is there an easier way to get the dynamic type than this?
if (!AllowChildDrop(e.Node, e.TargetNode, e.DropPosition, context.Answer.First().GetType(), context.Question.First().GetType()))
There is currently no way to avoid creating an instance to discover the runtime
Type
.You should use
DbSet.Create()
notFirst()
First()
instance may not be a proxy (e.g. you added an entity earlier in the call chain)see here for more information