views:

24

answers:

1

I have been looking at using Linq to entities with WCF for some projects that we are doing. Everything so far has worked out great but there is one thing that I am not so sure about. Linq-to-entities is creating objects which have EntityKey and ExtensionData properties. I am happy about their access in the service but concerned about the fact that clients seem to have access to this too seeing as they are public properties in the EntityObject class.

It seems to me that this causes a leaky implementation because the client should not be aware of the fact that this object was obtained using linq-to-entities.

+1  A: 

You can't change the access modifier because EntityKey property is inherited from parent EntityObject class which shows it as public. ExtensionData property is not related to entity framework. It is defined by IExtensibleDataObject which is implemented in all WCF proxies generated from Visual studio or svcutil. Again you can't change its access modifier.

This is usally the reason why people don't expose entities as data contracts in WCF. If you use EF v4.0 you can use POCO classes or Self tracking entities instead of heavy Entities. If you don't use EF v4.0 you should create separate data transfer objects or try to implement DataContractSurrogates for your entities.

Ladislav Mrnka
Thanks Ladislav. I was hoping there was some black magic like I could point some configuration file to another root object to inherit from and the tools would generate the appropriate code. Unfortunately not. I guess I might have to take the POCO route. Thanks
uriDium