EF4 Cast DynamicProxies to underlying object

后端 未结 5 2205
青春惊慌失措
青春惊慌失措 2020-12-15 06:55

I\'m using Entity Framework 4 with POCO template.

I have a List where MyObject are dynamic proxies. I want to use the XmlSerializer to serialize this list, but I don

5条回答
  •  情话喂你
    2020-12-15 07:21

    I faced with the same issue in EF 5. I was trying to serialize my entity objects to XML. @Koreyam s answer gave me a hint. I developed it little bit more. Somewhere in my code i was calling the serializer like this

    string objXML = EntitySerializer.Serialize(entity);
    

    Serialize method is generic. So method header is like this :

    public static string Serialize(T tObj) where T : class, new()
    

    So in my method body i use value injecter :

    T obj = new T().InjectFrom(tObj) as T;
    

    it just solved my issue for all of my entitites.

提交回复
热议问题