Search code examples
wcfentity-frameworkentity-framework-4pocodto

Exposing Entity Framework classes via API - Good idea or bad


I've been developing a WCF service with an entity framework back-end. When it came to passing data between the WCF service and the client I'd considered using POCO's or DTO's before setting on POCO's. It was only when I started coding it I realised I've never considered using the EF entities for passing data between the client and the WCF server.

My question is this: is using the EF entities for data transfer between the WCF service and the client an acceptable choice or is it regarded as bad practice?

I hope this question doesn't come across as too subjective, but I'm trying to understand whether this is a possible design option rather than the best design solution for a problem (which would be a highly subjective question).


Solution

  • We consider this a bad idea.

    Your WCF interface is your contract with the outside world.

    A change in your internal database should not result in a change in your external contract. If your external contract is used by 10 other systems, the coordination work could be so large as to make any changes impossible.

    Of course there can be situations with a small system, with a single client, that has a short life span, where this could be appropriate.