I use JSON.net to serialize EntityFramework objects.
In the past, I created a class that applies the JsonIgnore attribute to a property, and then I set the “MetadataType” attribute of my main EntityFramework class for this newly created class.
Here is an example:
The class to be applied to the EF class:
public class Role_DoNotSerialize { [JsonIgnore] public string Users { get; set; } }
Partial class file for class EF:
[MetadataType(typeof(Role_DoNotSerialize))] public partial class Role { }
In the above example, the Users property will not be serialized when the Role object is serialized.
My problem is that the same method does not work when I add the EntityKey property like this:
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?
Amanda kitson
source share