开发者

Is there a way to change EntityKey and ExtensionData access to protected when using Linq-to-entities and WCF?

开发者 https://www.devze.com 2023-01-17 00:11 出处:网络
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 o开发者_Python百科ne thing that I am not so sure about.

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 o开发者_Python百科ne 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消