开发者

How do I access the underlying type of a proxied type in entity framework 4.1

开发者_JS百科

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜