Search code examples
wcfentity-frameworkstrongly-typed-dataset

Should I use Datasets or Entity Framework to transfer data via WCF services?


I am working on a application design and investigating on passing data between WCF services and the ASP.NET web application. Options I am looking at are to either use "Datasets" or Entity Framework.

I have bunch of questions,

  1. If I use Entity Framework to pass data, would it add more overhead to the WCF communication,
  2. Is Datasets considered as "light weight" considering the communication overhead,
  3. If i use Entity Framework, how can I maintain object models if I use stored procedures to return complex data?

Overall I need to figure out pros and cons of using these technologies.


Solution

  • Your question touches on the principles of service-oriented architecture (SOA). In SOA, a service should expose operations (methods) that apply to business objects through contracts. The business objects should be defined in a standard way which is why WCF uses WSDL and XML Schema to do this.

    An SOA tenet is that business objects are shared through a schema and/or a contract but not as a specific implementation. By this priniciple, Dataset is a heavyweight, .NET specific, database-oriented object which should not be used to represent a business object. The Microsoft Patterns & Practices group apparently disregards SOA tenets since it shows how to use Dataset as Data Transfer Objects. Whether they're just promoting vendor lock-in or just trashing the whole concept of SOA is anybody's guess. If there is even the remotest chance your service will ever be consumed by a non-.NET client please do not use a Dataset.

    If you decide on using the Entity Framework then I'd recommend using Code First to define the Entity Framework data model and just expose those "code first" business objects in your service. This SO question & answers provide a good discussion on using Entity Framework with WCF.