Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want change Property Name in EF Entity to create Custome XML with Web Api.
my entity is
C#
public partial class foo
{
   public int ID{get;set;}
   public string Name{get; set;}
   public string LastName{get; set;}
}
and created Xml is
XML
 <foo>
    <name>Ali
    <lastname>Shahmohammadi
    <id>1</id>
</foo>
but i want have custome xml like
XML
 <foo>
    <firstname>Ali
    <family>Shahmohammadi
    <code>1</code>
</foo>


but i do not want decorate my entity foo class
i have a class like
internal class FooMetaData
{
public int ID{get;set;}
public string Name{get; set;}
public string LastName{get; set;}
}
and a partial class like
[MetadataType(typeof(FooMetaData))]
public partial class Foo
{

}

i want decorate FooMetaData Class to custome xml


What I have tried:

to learn
and created Xml is
Posted
Updated 22-Feb-17 22:47pm
v3
Comments
Patrice T 22-Feb-17 18:00pm    
And you have a question ?

Hello,

You just need to decorate your class.

[DataContract(Namespace = "")]
public partial class foo
{
    [DataMember(Name = "code")]
    public int ID { get; set; }
    [DataMember(Name = "Firstname")]
    public string Name { get; set; }
    [DataMember(Name = "Family")]
    public string LastName { get; set; }
}


Valery.
 
Share this answer
 
I hear that you don't want to decorate your classes with attributes but to do it totally POCO, there is a bit more work involved.

Check out Sam's Flickr.Net Lib. Here is how he does it with his Photo Class: flickr-net/Photo.cs at master · samjudson/flickr-net · GitHub[^].

My preference is not to do it Sam's way as there is more work to maintain it than using attributes and allowing the serialization process to do the work for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900