2

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~

skaffman
  • 398,947
  • 96
  • 818
  • 769
ypcheng
  • 21
  • 3
  • Answer is [here](http://stackoverflow.com/questions/25770369/get-underlying-entity-object-from-entity-framework-proxy/25774651#25774651). – Gert Arnold Sep 17 '14 at 13:40

2 Answers2

3

"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.

Alexander Christov
  • 9,625
  • 7
  • 43
  • 58
0

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;
}
Brian Low
  • 11,605
  • 4
  • 58
  • 63