【发布时间】:2019-09-13 18:24:52
【问题描述】:
我有两个从实体框架导入的 XML 可序列化类,父子类。总结成这样
[Table("OecPreorden")]
[DataContract]
public partial class OecPreorden
{
public OecPreorden()
{
OecPreordenProductos = new HashSet<OecPreordenProductos>();
}
[DataMember(IsRequired = false, Order = 1, Name = "ProductosComerciales")]
public virtual ICollection<OecPreordenProductos> OecPreordenProductos { get; set; }
}
[Table("OecPreordenProductos")]
[DataContract]
public class OecPreordenProductos
{
public OecPreordenProductos()
{
}
[XmlIgnore()]
public int Id { get; set; }
[DataMember]
[Required]
public long IdPromocion { get; set; }
[DataMember]
[Required]
public long IdProductoComercial { get; set; }
[DataMember]
[Required]
public long NroOrden { get; set; }
public int PreOrden_id { get; set; }
public virtual OecPreorden OecPreorden { get; set; }
}
当我看到 XML 时,它是这样显示的
<dir:ProductosComerciales>
<!--Zero or more repetitions:-->
<dir:OecPreordenProductos>
<dir:IdPromocion>?</dir:IdPromocion>
<dir:IdProductoComercial>?</dir:IdProductoComercial>
<dir:NroOrden>?</dir:NroOrden>
</dir:OecPreordenProductos>
</dir:ProductosComerciales>
因为它有零个或多个重复......它显示正确的标题与
<dir:ProductosComerciales>
我要改变的是迭代的标题..
<dir:OecPreordenProductos>
当我设置时
[XmlRoot("AAA")]
public class OecPreordenProductos
或
[XmlType(TypeName = "AAA")]
public class OecPreordenProductos
它不起作用,它仍然显示类名。
如何更改重复类的名称?
【问题讨论】:
-
您必须使用属性上方的 [XmlElement("AAA")] 在父级中更改它。
-
它不起作用..谢谢
标签: c# xml xml-serialization