如何在WCF Rest服务中序列化反序列化实体对象? [英] How to serialize an deserialize entity objects in WCF Rest services?

查看:90
本文介绍了如何在WCF Rest服务中序列化反序列化实体对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用实体框架数据库第一种方法创建示例wcf rest应用程序。我想将实体对象序列化和反序列化为xml格式。我能够使用自定义类而不是使用实体类进行序列化,但无法序列化和反序列化实体对象(喜欢Person,PersonEmails)。

我的XML格式如下

I create sample wcf rest application using entity framework database first approach.I want to serialize and deserialize entity objects to xml format.I am able to serialize with custom classes instead of using Entity classes but unable to serialize and deserialize entity objects (like Person, PersonEmails).
My XML format like below

<person>
<name>XXX</name>
<personemails>
<personemail>
<email>test@abc.com</email>
<personemail>
</personemails>
</person>



这里PersonEmails是Person Entity的导航属性



任何人都可以帮助我如何使用实体对象来帮助我。



提前谢谢。


Here PersonEmails is the navigation property of Person Entity

Anybody help me how to do this using entity objects.

Thanks in advance.

推荐答案

你不能这样做.B'cos我们不能对EF导航属性进行序列化。



所以在这里你必须创建普通的旧类对象(PO​​CO)(即自定义类)之后将导航属性值分配给它,然后使用那些普通对象(只有原始数据类型)进行映射。



< a href =http://stackoverflow.com/questions/250001/poco-definition>什么是POCO?
You cannot do this.B'cos we cannot do serialization the EF navigational properties.

So here you have to create Plain Old Class Object(POCO)(i.e. custom class) and after that assign your navigational property values into that and then use those plain objects (which are only having the primitive data types) for your mapping.

What is POCO ?


这篇关于如何在WCF Rest服务中序列化反序列化实体对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆