I have an Entity Framework Table per Type hierarchy like this:
public class WorkItem
{
public int WorkItemId {get;set;}
}
public class CancelingWorkItem : WorkItem
{
public int WorkItemIdToCancel {get;set;}
[ForeignKey("WorkItemIdToCancel")]
public virtual WorkItem WorkItemToCancel {get;set}
}
public class SomeOtherWorkItem : WorkItem
{
// more fields...
}
When I return a list of all WorkItems
in the database as Json, any serialized CancelingWorkItem
will contain the full definition of the WorkItemToCancel
field. I could just ignore this field with JsonIgnore
, but I was wondering if there was a different/better way of doing this. My repository project doesn't yet rely on Json.Net, so if I can instead tell the controller not to serialize that field, that might be a better solution.
You can use the
IgnoreDataMemberAttribute
attribute - It's not from an external library likeJsonIgnore
and I think that the default serializer and Json.NET will both recognise this attribute.