I'm using WCF Data Services 5.6 with custom entity classes, and successfully reading data into entities which inherit from Catel's ModelBase. However, when I try to perform an insert or update back, the reflection used by Data Service fails on one of ModelBase's readonly properties "ValidationContext" which implements an interface that has no setters. The ValidationContext has both an [XmlIgnore] and [Browsable(false)] attribute defined within Catel.
I've tried removing the property in both the Configurations.RequestPipeline.OnEntryStarting and OnEntryEnding hooks, and also via the (older school) method of editing the xml in the WritingEntry event. But the exception below arises before any of these events get triggered.
So it looks like the Data Services Client is reflecting on the type before attempting to serialize, and spitting the error there because it can't interpret an IValidationContext as a valid entity type in the model.
One workaround I've successfully tested is to effectively replace the public ModelBase property with a non-public version:
internal new IValidationContext ValidationContext
{
get { return base.ValidationContext; }
}
but this obviously isn't acceptable because then I can't use the ValidationContext elsewhere.
I believe this would also be a problem with proxies generated via "Add Service Reference" if you were to add any properties like this in counterpart partial class code for any entities.
Any advice? Can we replace/override any of the relevant Serializer methods?
The type 'Catel.Data.IValidationContext' has no settable properties. Source: Microsoft.Data.Services.Client at System.Data.Services.Client.ClientEdmModel.GetOrCreateEdmType(Type type) at System.Data.Services.Client.Metadata.ClientTypeUtil.TypeIsEntity(Type t, ClientEdmModel model) at System.Data.Services.Client.ODataPropertyConverter.TryConvertPropertyValue(ClientPropertyAnnotation property, Object propertyValue, HashSet
1 visitedComplexTypeObjects, ODataValue& odataValue) at System.Data.Services.Client.ODataPropertyConverter.PopulateProperties(Object resource, String serverTypeName, IEnumerable
1 properties) at System.Data.Services.Client.Serializer.WriteEntry(EntityDescriptor entityDescriptor, IEnumerable`1 relatedLinks, ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateRequestData(EntityDescriptor entityDescriptor, ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateChangeData(Int32 index, ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BatchSaveResult.GenerateBatchRequest()
at System.Data.Services.Client.BatchSaveResult.BatchRequest() at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options) at System.Data.Services.Client.DataServiceContext.SaveChanges()