views:

35

answers:

2

I've got new project on the go and I'm looking at using the Entity Framework (v4) over a WCF service.

I was wondering what peoples views are on the best way of delivering the data from EF over WCF? Should I be using the EF generated classes or wrap them up into something else?

The consuming application will be web for the moment, but possibly others in the future (Silverlight, Windows, mobile etc).

+2  A: 

For Silverlight i would recommend the WCF RIA Services. For web you could use ADO.NET Data Services.

Or you could get a little lower level and write your own bare bones WCF service and surface simple POCOs as transfer objects. This method is the most code-intensive and not for the faint of heart.

Jason Miesionczek
+2  A: 

In EF 3.5, my advice would be to never return an EF entity. Return a DTO instead, with properties that correspond to those of the EF entity.

In EF 4.0, they've done a lot of work around POCO classes and other things. I'm not up to speed on what they've done. If you can get EF to generate entity classes that do not expose implementation dependencies to clients, then you can return those. The .NET 3.5 classes derived from EF-specific classes, and the base class properties leaked out into the client proxies. You need this to not happen.

John Saunders
+1 An EF entity contains artifacts that betray it's origin.
DaveB
@DaveB: Even in .NET 4.0?
John Saunders
@John Saunders: My comment pertains to EF v1.0 only! I should have referenced the version. I haven't done anything with v4. I will wait for the final release.
DaveB