views:

79

answers:

1

I've created POCO classes with T4 Templates for EF 4.0 and generated mock for Context. Everything was great, but i don't like to initialize even small Mock-DB in C# code, so i've created some functions which generates Mock-DB from real DB and i wanted to serialize this object and use it later in some Unit Tests...

XML serialization fails, so i've tried binary serialization and serialization succeed, but deserialization failed.

Deserializer cannot find assembly "EntityFrameworkDynamicProxies-". How can i deserialize such thing (DynamicProxy?)...

+1  A: 

Dynamic proxies only exist on-demand, so are poor choices for serialisation. What us the error with XML? Ultimately I expect your best option here is to use a DTO layer, but that might also serialize with some other serializers. For example have you tried DataConttactSerializer, which may be able to cope? I've been adding proxy support to my own serializer but I haven't tried with ef4 yet.

Marc Gravell
I don't know, is it worth my effort.I just want to create small part of big DB, which can be used easily in Unit Testing. It should be static, so i thought serializing would be the best and the fastest way.I haven't tried DataContractSerializer, but i'm thinking also about other possiblility... Is there any way to get real object from proxy object? What am i doing right now is traversing through DB, starting point is one entity, and i'm fetching all dependencies adding them to MockContext (which is based on List<>),so mayby during adding object to MockContext i could skip proxy.Is it possible?
Simon
While serializing via XML, i got XmlInclude errors. Serializer find unexpected type and i should add XmlInclude to types which aren't known statically...
Simon
@Simon - yes, that is what I *expected*, but wanted to be sure. I don't know enough about the EF implementation to know about that, but that *is* possible with NHibernate, I expect it is possible. But you'd have to google it. DTO is simpler...
Marc Gravell
I know NHibernate is capable of such things :) But i have to deal with EF 4.0, unfortunately. I don't think DTO is better and i wanted to avoid it. I've tried to google it, but it's not as easy :)
Simon
@Simon - try `ProxyDataContractResolver` + `DataContractSerializer`? http://msdn.microsoft.com/en-us/library/dd456853.aspx
Marc Gravell
I'm not familiar with WCF. I've added attributes to my interface (Context and MockContext both inherit from this interface) but when i'm serializing via BinaryFormatter i got serialized Proxies, and XmlSerializer still have troubles - no reflecting type error, cannot serialize ICollection[<...>]. How can i make use of those attibutes during serialization?
Simon