我有个实体类 public class terminal
{
public int ID { get; set; }
public string termNO { get; set; }
}
在WCF服务中继承了它
[DataContract]
public class term : terminal
{
}
这个要不要序列化,如果需要,怎么去序列化
WCF中继承了实体类,怎么对其序列化
答案:5 悬赏:0 手机版
解决时间 2021-02-20 17:53
- 提问者网友:浪荡绅士
- 2021-02-19 19:34
最佳答案
- 五星知识达人网友:一把行者刀
- 2021-02-19 20:20
[DataContract(IsReference=true)]
public class Student
{
public Student()
{
this.Teachers = new HashSet();
}
[DataMember]
public int ID { get; set; }
[DataMember]
public virtual string Name { get; set; }
[DataMember]
public virtual ICollection Teachers { get; set; }
}
[DataContract(IsReference = true)]
public class Teacher
{
[DataMember]
public int ID { get; set; }
[DataMember]
public virtual string Name { get; set; }
}
public class Student
{
public Student()
{
this.Teachers = new HashSet
}
[DataMember]
public int ID { get; set; }
[DataMember]
public virtual string Name { get; set; }
[DataMember]
public virtual ICollection
}
[DataContract(IsReference = true)]
public class Teacher
{
[DataMember]
public int ID { get; set; }
[DataMember]
public virtual string Name { get; set; }
}
全部回答
- 1楼网友:我住北渡口
- 2021-02-20 00:44
有传输/保存的要求就需要序列化。直接给基类加[Serializable()] 特性就行了
- 2楼网友:低音帝王
- 2021-02-20 00:25
[DataContract]
public class term : terminal
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string termNO { get; set; }
}
- 3楼网友:痴妹与他
- 2021-02-19 22:51
截止至.net 4.0总共有如下若干个序列化类
1.xml序列化 xmlserializer
2.二进制序列化 binaryformatter
3.soap序列化 soapformatter
4.wcf序列化 datacontractserializer
5.json序列化 datacontractjsonserializer和javascriptserializer
- 4楼网友:蕴藏春秋
- 2021-02-19 21:16
[DataContract]
[KnownType(typeof(term))]
public class terminal
{
public int ID { get; set; }
public string termNO { get; set; }
}
[不用加DataContract]
public class term : terminal
{
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯