Getting Entity Data into Your Web Application

A friend said to me the other day “so, now that I have all of my data modeled as entity data using the Entity Framework, how do I get it into my web application?” While I will admit to not being an ASP.NET expert (despite having written some of the EntityDataSource web service control documentation), I have recently been investigating support for displaying OData feeds in web apps, so I thought that I would take a stab at enumerating the options that I have found for displaying entity data on the web. 

Silverlight Application

Displaying entity data in a Silverlight application is probably my personal favorite, since it leverages OData and I now know Silverlight pretty well. Silverlight is great (very “Flash”-y) and supports nice stuff like data binding. Since it’s a browser control, it behaves more like a client app (great for non-web devs like me). Plus it even runs out of the browser now. To consume entity data into a Silverlight application, you have two basic options:

OData Feeds

When you expose entity data via WCF Data Services, data is accessed by using the Open Data Protocol (OData). Silverlight includes a rich client for consuming OData feeds, the WCF Data Services client for Silverlight. Create an OData service when you want your data to be available to applications other than just Silverlight. Also, an OData service will work across domains. This quickstart shows how to consume an OData feed in a Silverlight client application (or watch this video). To see how to create the OData service that exposes Entity Framework data by using WCF Data Services, see this quickstart (or watch this video).

WCF RIA Services

Rich Internet Application (RIA) Services is a Silverlight-specific data access strategy that involves generating WCF endpoints for all CRUD operations against an entity data model. It is designed for same-domain, “end-to-end” Silverlight applications. This quickstart shows you how to access Entity Framework data in an Silverlight application by using WCF RIA Services.

JavaScript and OData

As I mentioned earlier, OData is an excellent way to expose entity data in the web. Since OData is accessed via HTTP and returns XML or JSON, it is also perfect to use in a web site that uses JavaScript. The following libraries can be used to access an OData service to display entity data in a web page by using JavaScript:

AJAX

You can use the ASP.NET AJAX library to access an OData service. There are quite a few examples how to do this on the ASP.NET site.

JQuery

You can also use JQuery to access OData, as Shawn Wildermuth demonstrates in his informative blog post: WCF Data Services and jQuery.

datajs

A newcomer on the scene, the datajs library is designed specifically for OData and HTML5, with some OData examples here.

ASP.NET EntityDataSource Web Server Control

Use the ASP.NET EntityDataSource web server control to display data by directly binding entity data to controls in an ASP.NET web page. This control enables you to access the entity data model exposed by Entity Framework directly and bind the data directly to web controls. This quickstart shows how to use the EntityDataSource web server control, and there is another useful EntityDataSource tutorial on the ASP.NET site.

ASP.NET MVC

You can use an Entity Framework data source with an ASP.NET MVC application, as demonstrated in this tutorial. I’ve never tried to use MVC, but I applaud the model-view-controller pattern as I use the related model-view-view-model (MVVM) pattern in my Windows Phone 7 apps.

ASP.NET Dynamic Data

While I don’t know much about ASP.NET Dynamic Data, apparently it uses this same EntityDataSource control in the data scaffolding. This walkthrough shows how to use Entity Framework with Dynamic Data.

. . . . .

Please let me know if I left anything out.