开发者

EF Codefirst How to Load Object Hierarchy with Dynamic Proxy turned Off

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 tr开发者_运维技巧ied 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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜