0

I need to serialize an object to pass it as a parameter in a webservice. I followed the recommendations the the article: DataContractSerializer Error using Entity Framework 4.0 with WCF 4.0

This Object is quit complex because it resembles a hierarchical data structure.

Now I have a problem, because the related objects (one to many objects) are not loading and their value is null.

This is not a problem if I use Dynamic proxies, however dynamic proxy objects do not serialize for use in a webservice.

I have tried to turn on / off lazy loading in the dbContext but it made no difference.

Any one knows how I can work around this problem, perhaps even loading a proxy object and copying it to a 'Real' Object?

Thanks

Community
  • 1
  • 1
Adrian Hedley
  • 1,541
  • 1
  • 16
  • 28

1 Answers1

0

If it's a relationship that you really must have, your best bet is to load the data using the normal dynamic proxy object and use something like AutoMapper (or a manual conversion) to convert it into whatever you want to send across the service. You can then ensure that what you want to send gets loaded and populated.

Trying to tell EF and WCF to know how to automatically get it right for a complex hierarchical object just isn't worth the effort compared to doing the loading/conversion manually.

Tridus
  • 5,021
  • 1
  • 19
  • 19
  • Hi, thanks for the Tip. What do you mean exactly by Auto Mapper?, I am trying to avoid the manual conversion if possible. – Adrian Hedley Jun 02 '11 at 13:57
  • [AutoMapper](http://automapper.codeplex.com) is a library that can automate some of the manual conversions. It tries to figure out what maps to what between two classes without you having to write code to do it. In a case like this it can help reduce the effort required to set the conversion up. I do think you'll have to convert in some way though, trying to make EF and WCF play nice on this is very tricky with complex data structures, while doing it manually is easy (and reliable). – Tridus Jun 02 '11 at 14:07