2
votes

I'm trying to use Entity Framework 5.0 (Model-First approach) with WCF Data Services 5.6.2 and ran into following trouble:

When Entity Data Model for WCF Data Service contains Enum property when Data Service will fail at initialization stage:

The server encountered an error processing the request. The exception message is: "The property 'X' on type 'Y' is of type 'enum-type-here' which is not a supported primitive type."

The exception stack trace is:

System.Data.Services.Providers.ObjectContextServiceProvider.PopulateMemberMetadata(ResourceTypeCacheItem resourceTypeCacheItem, IProviderMetadata workspace, ProviderMetadataCacheItem metadataCacheItem, PrimitiveResourceTypeMap primitiveResourceTypeMap) at System.Data.Services.Providers.ObjectContextServiceProvider.PopulateMetadata(ProviderMetadataCacheItem metadataCacheItem) at System.Data.Services.Providers.BaseServiceProvider.LoadMetadata(Boolean skipServiceOperations) at System.Data.Services.DataService1.CreateInternalProvider(Object dataSourceInstance) at System.Data.Services.DataService1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider& metadataProviderInstance, IDataServiceQueryProvider& queryProviderInstance, Object& dataSourceInstance, Boolean& isInternallyCreatedProvider) at System.Data.Services.DataService1.CreateProvider() at System.Data.Services.DataService1.HandleRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

The only advise I've found to fix the issue is marking such properties as [NotMapped], but when I annotate T4 generated classes' enum properties with this attribute it does nothing and Data Service still fails.

Also EF provider for WCF DS doesn't support System.Data.Services.IgnorePropertiesAttribute that could be used to hide enums only with Reflection provider.

How can I expose strings instead of DB stored int-backed enum values using WCF Data Services?

1
I would be happy with just the int valueJerther

1 Answers

2
votes

The facts that "EF provider for WCF DS doesn't support System.Data.Services.IgnorePropertiesAttribute" and "EF provider also doesn't allow to expose any 'new' properties that aren't in the underlying EDM model" gives me a sad answer:

No, we can't expose Enums and even custom string representation for them using WCF Data Services with EF Provider.