I have an Entity Framework POCO class that is generated by a T4 Template.
I am planning to use the generated class as my data contract. However, it has a few properties that don't need to be in the contract. For example I have a property called AddressId. It is the foreign key to the address table. Since the actual address is attached to the object I don't want the AddressId to be visible to the client.
I could modify the T4 template, but I would rather not.
I saw this post that showed how to use 'MetadataType' to add attributes to existing properties in partial classes. This is the example that they gave:
[MetadataType(typeof(Dinner_Validation))]
public partial class Dinner {}
public class Dinner_Validation
{
[Required]
public string Title { get; set; }
}
But I tried that for my class (using [IgnoreDataMember]) and it does not work (the AddressId is still shown).
How can I hide this one property without having to make a whole new class to copy all my data into?