views:

53

answers:

2

Given that directly exposing linq to sql or entity framework classes over web services is a bad idea, how should I expose the data over a web service such as WCF?

It seems like I would have to create a parallel set of classes for the web service, and then marshal the data into those, which doesn't seem very elegant.

The web services will be custom, so something like RIA is not very useful in this case.

+1  A: 

Have you seen OData and WCF Data Services? Here is a great talk by ScottHa: http://www.hanselman.com/blog/ODataBasicsAtTheAZGroupsDayOfNETWithScottGu.aspx

OData, through WCF Data Services, works seamlessly with EF 4.

Daniel A. White
@Daniel: thanks for the references. I think WCF Data Services falls in the same boat as RIA Services for my purposes.
ngoozeff
+1  A: 

You can use the support for POCO (Plain Old CLR Objects) in EF 4 to expose the entity model as simple objects. The designer supports converting entity data model into POCO objects.

Specifically for WCF service scenario, you could also use the self tracking entities T4 template available in EF 4 when you try to add new item to the project.

I hope following link will be helpful to you

http://blogs.msdn.com/b/efdesign/archive/2010/03/10/poco-template-code-generation-options.aspx

http://blogs.msdn.com/b/adonet/archive/2010/01/25/walkthrough-poco-template-for-the-entity-framework.aspx

http://stackoverflow.com/questions/2464909/generate-poco-classes-in-different-project-to-the-project-with-entity-framework-m

Nilesh Gule