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.
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
Generate POCO classes in different project to the project with Entity Framework model
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.
Related
My Question is about returning EF entity using WCF service. As wcf required Data Members for returning data. Solution i have to do mapping of entity to WCF data members which is quit hectic.
Is there possible solution which reduce my work effort. I tried EntityFramework with WCF - how to return EF entities but available solution have support for vs2010
only.
This is tricky question. You want to pass EF entities through WCF. This is bad in some way, because EF objects are burdened with additional data provided by EF (e.g. for change tracking purposes). The best way to pass objects through domains in your application is create DTO objects. To do that, you can develop additional mappings (with usage of T4 templates) that create this DTOs based on your existing EF entities.
I am doing some prototyping and have a small database (4 related tables) which I developed an Entity Framework 6 project around (DLL with models for the tables). I've added an ASP.NET MVC 4 Web App to the solution that includes Repository interfaces/implementations under the model folder. The Repositories add interfaces for CRUD operations against the EF project. The Web App has a set of controllers providing REST interface through the repositories. Standard stuff I believe.
The issue that I have is I want to create an aggregate class the wrappers types (models) defined in the EF and return that aggregate in response to a Get request. The question is where do I define this aggregate object? The EF project? (and how?). An independent class library (usable by a client)? The Web App?
Trying to keep all the model definitions in the same place that understood by a client and Web App service at the same time.
Thanks
I believe what you want here is the DTO (Data Transfer Object) pattern. See here and here for basic explanation of the pattern. The idea is that you define a set of classes distinct from your data access objects (EF classes in your case), whose purpose is to relay data between your REST interface and its clients. If you have C# clients to whom you want to make the class definitions visible for simplicity then I would suggest putting the DTO class definitions in their own class library project and have the server and client both reference that dll.
Please bear with me as I am new to MVC and WCF and may be asking the wrong question.
I am trying to write a WCF service and an MVC web application over an existing project that contains entity, data and business layers. The MVC and WCF components would then replace an older web service and WebForms application which worked very diferently and did not use modern practices.
I see the need to generate DTO objects against all Entity objects and was wondering how we can generate them. Through reflection, digging into the DbContext or some other method.
Furthermore, I also want to generate repository partial classes minimizing the need to maintain hand-written code for a large data model.
How do large development teams do this?
I am new to Silverlight and am developing an ASP.NET web application that requires a Silverlight project to record webcam audio/video streams.
The solution consists of a library project containing business entities such as [User], [BillingInfo], etc., and an ASP .NET Web Application.
Since Silverlight does not support EF, how can I use the strongly-typed entity objects from within Silverlight? I do not need access to the Context object but will require access to Entity classes.
I use Code First so have to mark Entities with Annotations which Silverlight will not recognize since the DataAnnotations assembly is not referencable. Switching to model-first is also an option (albeit less preferable) if required.
Has anyone dealt with a similar scenario? What is the best way to get strongly-typed entities in Silverlight. Any articles or references would help as well. Thank you.
Technologies (upgrade is an option if required):
ASP .NET Web Application (.NET 4)
Entity Framework 5
Silverlight 5
I would recomend giving WCF RIA Services a try. This will simplify the data access for your application and provide you with strongly typed entities on the Silverlight client side.
Silverlight works very well with entity framework!
You could directly consume your entity through webservices as describe in this blog: http://geekswithblogs.net/berthin/archive/2011/05/29/ado_net_entityframework_from_silverlight.aspx
Or as Dave suggest, you could combine RIA services and Entity Framework, so you could use annotation http://blogs.msdn.com/b/brada/archive/2010/03/15/silverlight-4-ria-services-ready-for-business-exposing-data-from-entity-framework.aspx
The combination of Silverlight and Entity Framework create a really powerfull ready to use business logic.
Ive been playing around with the entity framework with an idea for creating a web service to be consumed by an application in sharepoint that a 3rd party developer is creating. Basically i need to return a list of jobs e.g list based on some search criteria. I wanted to use the EF so i have something scalable however it seems returning POCO's from a web service is harder than i imagined it to be. Are web services and EF / POCO's meant to work together. Does anyone have any good examples or can point me to some.
Are web services and EF / POCO's meant to work together.
Yes. The only thing you must to ensure is to make your entities serializable - POCO entities can contain circular references which are not serializable by default.
What about consuming the web service? I read somewhere that the consumer has to reference the entity namespace to use the returned objects.
This is not true with POCOs. This is only true with Self tracking entities.