Book Image

Entity Framework Tutorial (Update) - Second Edition

By : Joydip Kanjilal
Book Image

Entity Framework Tutorial (Update) - Second Edition

By: Joydip Kanjilal

Overview of this book

The ADO.NET Entity Framework from Microsoft is a new ADO.NET development framework that provides a level of abstraction for data access strategies and solves the impedance mismatch issues that exist between different data models This book explores Microsoft’s Entity Framework and explains how it can used to build enterprise level applications. It will also teach you how you can work with RESTful Services and Google’s Protocol Buffers with Entity Framework and WCF. You will explore how to use Entity Framework with ASP.NET Web API and also how to consume the data exposed by Entity Framework from client applications of varying types, i.e., ASP.NET MVC, WPF and Silverlight. You will familiarize yourself with the new features and improvements introduced in Entity Framework including enhanced POCO support, template-based code generation, tooling consolidation and connection resiliency. By the end of the book, you will be able to successfully extend the new functionalities of Entity framework into your project.
Table of Contents (16 chapters)
Entity Framework Tutorial Second Edition
About the Author
About the Reviewers

REST and REST-based service frameworks

Representation State Transfer (commonly known as REST) is an architectural paradigm that is based on the stateless HTTP protocol and is used for designing applications that can intercommunicate. In REST, resources are used to represent state and functionality, and these resources are in turn represented using user-friendly URLs. Note that the REST architecture style can be applied to other protocols as well. The word "stateless" implies the HTTP/HTTPS protocols. The REST architectural style is popular in the HTTP world and gives better results when used in combination with the HTTP protocol.

The key goals of REST include the following:

  • Scalability

  • Compatibility with other technology and platforms

  • Generality of interfaces

  • Discoverability; that is, interconnectivity between resources

  • Components that can be deployed independently of one another

  • Reduced latency

  • Better security

  • Extensibility

A RESTful Web API is a web API that conforms to the REST principles. The main principles of REST include:

  • Identification of resources

  • Stateless communication

  • Manipulation of resources through representations

  • Self-descriptive messages

In this section, we will examine the popular REST-based service frameworks.

Here is the list of the popular REST-based service frameworks or APIs:

  • Ruby on Rails

  • Restlet

  • Django

  • Flickr

  • Google

  • Yahoo

Ruby on Rails

Ruby on Rails is an optimized open source web application framework that runs on top of the Ruby programming language. Ruby on Rails follows the basic software engineering patterns and principles. The Rails Web API is a framework that facilitates the creation of web applications based on the Model-View-Controller (MVC) framework. The view layer is composed of "templates," and most of these templates are HTML-based with embedded Ruby code. The model layer represents the domain model, the business logic classes, and the data access classes. The controller layer handles incoming HTTP requests. Note that the Rails controller can generate XML, JSON, PDFs, and also mobile-specific views. You can get more information on this framework from


Restlet provides support for an extensive list of extensions that include the following:

  • Spring

  • WADL

  • XML

  • JSON


The benefits of Restlet include the following:

  • Support for a fully symmetric client and server API

  • Support for connector protocols other than HTTP

  • Support for complete URI routing control through the Restlet API

  • Fast and scalable

  • Powerful filtering support

  • Support for a consistent client and server API

You can explore more on this API from

Django REST

The Django REST framework provides a powerful and flexible API, using which you can build Web APIs seamlessly. This API provides an extensive documentation and excellent community support. You can know more about this framework from

The Flickr REST API

The Flickr REST API is simple and easy to use. Flickr also has some JSON APIs that you might make use of for invoking the API through JavaScript. You can get more information about this from

The Google API

The Custom Search JSON/Atom API from Google enables developers to write applications that can leverage this API and retrieve and display custom search in the applications. This API allows you to use RESTful calls for web search and get the results in JSON or Atom format. You can know more on this API from

Note that Google provides a much wider range of API services than APIs, such as Google Maps, AdWords, Translate, Google Analytics, and so on.

Yahoo Social REST APIs

The Yahoo Social REST APIs provide a collection of URI resources that can provide access to the following:

  • Users' profiles

  • Status messages

  • Status updates

These URIs are actually grouped into APIs, depending on the information that they return. For more information, you can refer to

Exploring OData

The Open Data Protocol (OData) is a protocol that is built on web standards, such as HTTP, Atom, and JSON, and standardizes how data is exposed and consumed. It is a data access protocol that provides a uniform way of performing CRUD operations on the data. It is used to expose and access information from different data sources; that is, relational databases, filesystems, content management systems, and so on.

OData is a standardized protocol that builds on top of core protocols, such as HTTP and architecture paradigms, such as REST. Like RSS, Atom is a way to expose feeds. Note that AtomPub makes use of HTTP verbs such as GET, POST, PUT, and DELETE, to facilitate the publishing of data. OData v4 is now an OASIS standard. It is an open protocol that enables the creation and consumption of queryable and interoperable RESTful APIs.

OData is a REST-based protocol that uses HTTP, JSON, and ATOM, and supports any platform that has support for HTTP, XML, or JSON. You can use it to expose data retrieved from relational databases, filesystems, or data services. OData enables you to perform CRUD operations on top of a data model or a data service. In essence, it is an HTTP-based, platform-independent protocol that supports REST. In OData, data is provided through the usage URIs and common HTTP verbs, such as GET, PUT, POST, MERGE, and DELETE. Note that WCF Data Services (previously known as ADO.NET Data Services) is the implementation of OData Protocol in .NET applications.

The official website of OData Protocol exposes data as an OData Service. The service URL is

When you open the page in a browser, this is what the XML markup looks like:

<service xml:base="">
<collection href="ODataConsumers">
<collection href="ODataProducerApplications">
<collection href="ODataProducerLiveServices">