[DataContract]
public class Foo
{
[DataMember]
public Id { get; set;}
[DataMember(Name = "Jack"]
public string Bar { get; set;}
[DataMember(Name = "Jane"]
public string Baz { get; set;}
public int Fizz { get; set; }
[NotMapped]
public bool Buzz { get; set;
}
I have tried using the DataMember attribute, but it does not work. The "Jack" is not mapped to the Bar.
I have spent some time to debug the OData.Client codes and find out the ClientTypeUtil.GetServerDefinedName function is checking the OriginalNameAttribute .
After I change the model to use OriginalName, it works.
public class Foo
{
public Id { get; set;}
[OriginalName(Name = "Jack"]
public string Bar { get; set;}
[OriginalName(Name = "Jane"]
public string Baz { get; set;}
public int Fizz { get; set; }
[NotMapped]
public bool Buzz { get; set;
}
I check the OData documentation, it does not have any document talking about this.
My questions are:
Is it the right way to use OriginalNameAttribute to do it?
Is there any attribute like the NotMapped to tell that property should not be mapped? Is it the IgnoreClientPropertyAttribute?
Can you add documentation about using the OriginalNameAttribute to do this mapping? I think some people may need it too as I have spent a day or more to find it out.
I need to have a entity model that has different property name from the OData one, I need to map them like using the JsonPropertyName.
I find this stackoverflow link and this ODataSamples page saying it can use the DataContract/DataMember like this:
I have tried using the DataMember attribute, but it does not work. The "Jack" is not mapped to the Bar.
I have spent some time to debug the OData.Client codes and find out the ClientTypeUtil.GetServerDefinedName function is checking the OriginalNameAttribute .
After I change the model to use OriginalName, it works.
I check the OData documentation, it does not have any document talking about this.
My questions are:
Thanks.