Implementing WCF Data Service without Entity Framework RRS feed

  • Question

  • Hi,

      I would like to know if there is a way to implement WCF Data Services exposing data from SQL Server without using Entity Framework. I did some search on the internet and most samples seem to suggest that we have load the entire data in memory. 




    Friday, December 10, 2010 3:36 PM

All replies

  • Hi,

    You have effectively 3 options:

    1) Entity Framework. By far the easiest solution. Why do you need to not use it?

    2) Reflection provider
    2a) Load everything in memory - not a great solution if you have lot of data
    2b) Use for example LINQ to SQL as the LINQ provider for the reflection provider. This has some known limitations though.

    3) Write a custom provider - full control over everything, but lot of work to implement.

    In any case, I would try to make EF work for my scenario as that is possibly the easiest solution.


    Vitek Karas [MSFT]
    Friday, December 10, 2010 6:35 PM
  • Hi

    Not sure why you dont want to use EF - but nevertheless - oData or WCF Data Service - has only 1 mandate when it comes to exposing data using this technology. Any POCO class i.e. Plain Old CLR Object which is of type IQueryable can be exposed via WCF Data Service. Meaning IQueryable allows you to pwerform GET on your resources. If you need the WRITE support your classes will need to implement IUpdatable.

    You can look at the following example of mine. Here i have created a POCO class called Person. Then a business class called PersonService which exposes a property called People which is of type IQueryable<Person>. In the WCF Data Service i provide reference to person service and set up the entity access rules. Thats all its there to it.

    Here is the sample : http://cid-2386032d6b54669a.office.live.com/embedicon.aspx/Community/CTD%20Mysore%20Nov%2014/Exposing%20POCO%20Final.zip

    Pay attention to the web project. It contains Person.cs, PersonService.cs and Odata.svc.

    Let me know if this helps you.

    PS: mark this as an answer if this is what you have been looking for

    Monday, December 13, 2010 6:37 PM
  • Just a minor correction. With custom provider you don't even need the POCO classes, it's possible to expose data which are not stored/represented as CLR classes (and their properties) at all. A sample of how to write such a provider can be found in this blog series: http://blogs.msdn.com/b/alexj/archive/2010/03/02/creating-a-data-service-provider-part-9-un-typed.aspx


    Vitek Karas [MSFT]
    Monday, December 13, 2010 8:31 PM
  • One reason for not wanting to use EF is when you want the advantage of easily returning OData to your REST client, but the data doesn't come from a database. For example, I have a WCF REST service that returns photo collections from various third party social applications, like Facebook. Using a WCF Data service to automatically generate either an Atom or JSON response is attractive, but almost all data service examples assume you want to start with a SQL database and generate an entity model using the tooling. Thanks for posting your link, and also thanks to Vitek Karas in the following post for the other link.
    Sunday, February 27, 2011 8:58 PM
  • I want to implement WCF Data Service without Entity Framework in my company because the SQL Query are not authorized, only stored procedure can be called for performance reason. Actually in Entity Framework you can link Insert/Delete/Update to stored procedure but it's not possible to obtain data with SP.

    I try to use the library WCF Data Service toolkit with Visual Studio 2012 and I try to use this data service with a LightSwitch Silverlight Client. The get methods work, insert method work, delete method work but update method don't update the data and multiple change don't work too...

    A lot of samples exist with EF but in my case only old post (2010 or 2011) exists...

    Monday, June 3, 2013 3:07 PM