Reputation: 11
I'm working on an MVC3 application. I created my POCO classes through the ADO.NET DbContext Generator and I'm using partial classes to add validation on properties. Now, when I try to serialize one of my entities I receive this error:
"Cannot serialize member .... of type 'System.Collections.Generic.ICollection`1[....."
I googled this error and I discovered that it's possible to add the tag
[XmlIgnore]
to certain properties.
But the point is that I can't put this tag on the properties because they are
created everytime by the generator.
So how I can do this in a simpler way ?
Upvotes: 1
Views: 193
Reputation: 20240
The key is the MetadataTypeAttribute
. You can add this to your partial class which implements the additional properties and your validation logic. Then create a meta data class with a property of the same name of your generated class, and apply the attribute you need.
[MetadataType(typeof(MyPOCOMetaData))]
public partial class MyPOCO
{
// your partial validation code and properties
}
public class MyPOCOMetaData
{
[XmlIgnore]
public string GenerateProperyName { get; set; }
}
Upvotes: 1