I'm using WCF Data Services for a RESTful API that returns a JSON response.
consider this object:
[Table("person")]
public class Person
{
[Column("dob", TypeName = "datetime")]
public DateTime DateOfBirth { get; set; }
[NotMapped]
public int Age
{
get { return CalculateAge(); }
set { }
}
}
WCF does not treat this object as I would expect. My service request completely ignores the Age property in the serialization of the Person object.
I've been using a workaround where I map the Age property to a dummy database column and I create a setter that does nothing. What an ugly hack! Is there a better way to have a DataService return a property that is not mapped to a database column?
After much research, and no evidence to the contrary on stackoverflow, i'm going to go ahead and say the answer is: No. A WCF DataService with entities mapped using EntityFramework 4 can NOT return unmapped properties.
The ugly hack i've been using is this one, which requires you to acutally make a field in the database that just never gets read.