I’ve got a LINQ 2 SQL generated class I’d like to expose through a webservice.
There are some internal properties I don’t want to be available.
Normally I’d throw [XmlIgnore] in there but because the properties are in the generated half I can’t do that.
I’ve been looking at using MetadataType following this post which looks like it should allow me to define the property attributes in another class.
My code looks something like this:
[MetadataType(typeof(ProspectMetaData))]
public partial class Prospect : ApplicationBaseObject
{
}
public class ProspectMetaData
{
[XmlIgnore]
public object CreatedDateTime { get; set; }
[XmlIgnore]
public object AmendedDateTime { get; set; }
[XmlIgnore]
public object Timestamp { get; set; }
}
I’m referencing this through an ASP.NET Web Service from a Silverlight Project.
The issue is that the [XmlIgnore] attributes are being ignored, those properties are being sent through.
Does anyone have any insight into what might be going wrong here? and what might be the best way to do this?
AFAIK,
MetadataTypeAttributeis not supported byXmlSerializer(although it would be nice – I’ve simply never checked). And as you say, you can’t add member attributes in a partial class.One option may be to make the generated properties non-public (
private,protectedorinternal) – and name it something likeTimestampStorage(etc) – then re-expose them (in the partial class) on the public API:(since
XmlSerializeronly looks at the public API). The biggest problem here is that LINQ-to-SQL queries (Whereetc) will only work against the generated columns (TimestampStorageetc). I’ve used this approach before with the member asinternal, allowing my DAL class to use theinternalproperty… but it is a bit of a fudge.