How do I access the underlying type of a proxied type in entity framework 4.1
I have a dynamic proxy obtained via
var boo = context.Set<Boo>().Find(1)
how can I know the fact that boo is actually a proxy of Boo?
from debug console, I found out that the proxy kept this info in its local variable boo._entityWraper.IdentityType
but i don't know how to access it.
Any help will be highly appreciated~
"boo" is of either of Boo type or of Boo's proxy type. Try getting boo's type or boo's base type if you have the second case.
Some example code to supplement @achristov's answer:
private Type GetTypeOf(object o)
{
var type = o.GetType();
if (!type.Namespace.Contains("MyProject"))
{
// o is probably a proxy
type = type.BaseType;
}
return type;
}
精彩评论