8.13.5. Using EDM to create Entity Framework based applications

Now that a Microsoft Entity Data Model has been created for the Microsoft SQL Server Northwind database, Entity Framework applications can be created to make use of it.

Entity Frameworks based ADO.NET Data Service

An ADO.Net Data Service for the Microsoft SQL Server tables can be created using the Entity Data Model created in the Creating EDM in Visual Studio 2008 section .

  1. Open the


    project created in the Creating EDM in Visual Studio 2008 section .

  2. Select the Project -> Add New Item menu option.

    Figure 8.675. VirtuosoDataService


  3. The

    Add New Item

    dialog will appear. Choose the

    ADO.NET Data Service template

    . Give it the name


    , and click


    to create the ADO.Net Data Service.

    Figure 8.676. Add New Item

    Add New Item

  4. In the newly created


    Data Service file, add the data source class name of


    (note this is the name set in the Creating EDM in Visual Studio 2008 section) as the


    name. Enable the access to the Data Service by adding the entry

    config.SetEntitySetAccessRule("*", EntitySetRights.All);

    in the



    // C#
    using System;
    using System.Web;
    using System.Collections.Generic;
    using System.ServiceModel.Web;
    using System.Linq;
    using System.Data.Services;
    namespace SimpleDataService
        public class Northwind : DataService<VirtuosoDemoEntities>
            public static void InitializeService(IDataServiceConfiguration  config)
                config.SetEntitySetAccessRule("*", EntitySetRights.All);

    Figure 8.677. Virtuoso.svc.cs


  5. To test the Data Service, simply hit


    within Visual Studio. This will start the development web server, run the Data Services server inside and load a Web browser page displaying the list of available tables/entities for the Northwind database catalog.

    Figure 8.678. Data Service test

    Data Service test

  6. To access a specific entity instance like the


    table ALFKI record, use this convention http://host/vdir/Virtuoso.svc/Customers('ALFKI').

    Figure 8.679. EMPLOYEES



  1. Important

    - To view


    (the default format returned by an ADO.NET Data Service) in Internet Explorer, you must first ensure that

    Feed Reading View

    is turned


    . This can be done on the

    Content tab


    Tools in Internet Options


  2. If a Data Services entity instance URI page fails to load you can turn


    errors on by adding

    config.UseVerboseErrors = true;

    in the

    virtuoso.svc.cs InitializeService

    method to obtain more detailed information from the server as to why the page failed to load:

    public static void InitializeService(IDataServiceConfiguration config)
    config.UseVerboseErrors = true;
    config.SetEntitySetAccessRule("*", EntitySetRights.All);