I am using JSON.net to serialize my EntityFramework objects.
In the past, I have created a class that applies the "JsonIgnore" attribute to a property, and then I set the "MetadataType" attribute of my main EntityFramework class to that newly created class.
Here is an example:
The class that will be applied to the EF class:
public class Role_DoNotSerialize
{
[JsonIgnore]
public string Users { get; set; }
}
The partial class file for the EF class:
[MetadataType(typeof(Role_DoNotSerialize))]
public partial class Role
{
}
In the above example, the property "Users" will not be serialized when serializing a "Role" object.
My problem is, this same technique fails to work when I add in the EntityKey property like so:
public class Role_DoNotSerialize
{
[JsonIgnore]
public string Users { get; set; }
[JsonIgnore]
public System.Data.EntityKey EntityKey { get; set; }
}
Using this class, the "EntityKey" property is still serialized. What am I doing wrong?