开发者

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

开发者 https://www.devze.com 2023-03-13 22:00 出处:网络
开发者_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?
开发者_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

精彩评论

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

关注公众号