[Tutorial & Sample] WCF Data Services Entity Framework Provider is updated with WCF Data Service 5.6.2


After WCF Data Services Entity Framework Provider version 1.0.0-alpha2 was released, we got lots of valuable feedbacks from customers. Recently we summarized all the feedbacks and fixed the most critical bugs reported. Now we are happy to announce the release of WCF Data Services Entity Framework Provider 1.0.0-beta2 (Below using EF6 Provider beta2 for short).

  • Download sample code here.

Adopting EF6 provider beta2 in new service

1. Create a new project, an ASP.NET Empty Web Application in Visual Studio 2012 for example.

2. Install the EF6 Provider beta2 NuGet package. WCF Data Service 5.6.2 and Entity framework 6.0.1 will be installed as dependencies.

3. Create a data model with EF6

Follow instructions in this blog post to upgrade to EF6 and make sure you install EF 6.x DbContext Generator if using DB first development.

4. Add a new WCF Data Service 5.6.2. This item will be added into Visual Studio by installing WCF Data Service 5.6.2 tooling installer. (5.6.2 tooling installer will be published soon, currently you can add a WCF Data Service, and upgrade WCF Data Service dll to 5.6.2)

clip_image002

5. Replace the base type of the DataService that was generated by the item template with EntityFrameworkDataService. See the article What’s the difference between DataService and EntityFrameworkDataService for more details.

If you upgrade an existing service to EF6 provider beta2, you just need to upgrade EF provider Nuget package and make sure your data service inherits from EntityFrameworkDataService<T> where T is your data source class.

Bugs fixed in EF6 Provider beta2

Based on customers’ feedbacks of previous EF6 Provider, we got lots of bugs fixed in this version. Please refer to the release note for details. The top-voted issues “complex type” and “CurrentDataSource” are fixed as the highest priority.

1. Complex type can be serialized now

Complex type is supported in both DB First and Code First development. The following are examples of complex type scenario in each approach.

In DB First development, for example in DataBaseFirstSample, create a complex type “ShipInfo” in EF designer (Refer Complex Types in the EF Designer) to contain properties like “ShipName”, “ShipAddress”, etc. and class “ShipInfo” will be auto-created after saving.

Then complex property can be accessed with URL:

~/DataBaseFirstSampleService.svc/Orders(10248)/ComplexProperty/ShipCountry

In Code First development, for example in CodeFirstSample, define a class named “PostContent”:

Define property “content” based on “PostContent” in entity type “Post”:

Then complex property can be access with URL:

~/CodeFirstSampleService.svc/Posts(1)/Content/Title

2. CurrentDataSource on DataService class can be used to retrieve DBContext now

CurrentDataSource is used often in functions, and query or change interceptors. The following gives an example of using CurrentDataSource in function definition.

For example in DataBaseFirstSample service, define a function “GetOrdersCount” which accesses “Orders” through CurrentDataSource:

Then the function “GetOrdersCount” can be called with URL:

~/DataBaseFirstSampleService.svc/GetOrdersCount

Apologize that we do not have enough time to support Enum and Spatial types in this version, service would fail to access if Enum or spatial type exists in data model.

Open source

The EF6 provider source code has been released under Apache 2.0 license. You can download the code from our Git repository at https://git01.codeplex.com/odata, or view more about OData at https://odata.codeplex.com/ . We continues our commitment to open source, and we are happy to receive community contributions and feedbacks.

Comments (4)

  1. Michal M. Wozniak says:

    Thanks for the new release.

    The link  git01.codeplex.com/odata does not seem to work though.

  2. Zoe Luo says:

    @Michal, please try "git clone git01.codeplex.com/odata" to download the code.

  3. Ali Arslan says:

    There is a bug in WCF Data Services EntityFramework Provider 1.0.0-beta2; Though there was no problem with alpha version, now i can't add service reference to a wpf client aplicaion; I use database first approach and the problem is with some relationships in database and related associations in model, the sql script for the problematic tables and relationships in database is as follows:

    USE [MyDatabase]

    GO

    /****** Object:  Table [dbo].[Countries]    Script Date: 02.10.2014 13:00:05 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Countries](

    [Id] [tinyint] IDENTITY(1,1) NOT NULL,

    [Name] [nvarchar](50) NULL,

    CONSTRAINT [PK_Countries] PRIMARY KEY CLUSTERED

    (

    [Id] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    /****** Object:  Table [dbo].[Districts]    Script Date: 02.10.2014 13:00:05 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Districts](

    [Id] [int] NOT NULL,

    [ProvinceId] [int] NOT NULL,

    [CountryId] [tinyint] NOT NULL,

    [Name] [nvarchar](50) NOT NULL,

    CONSTRAINT [PK_Districts] PRIMARY KEY CLUSTERED

    (

    [Id] ASC,

    [CountryId] ASC,

    [ProvinceId] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    /****** Object:  Table [dbo].[Provinces]    Script Date: 02.10.2014 13:00:05 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Provinces](

    [Id] [int] NOT NULL,

    [CountryId] [tinyint] NOT NULL,

    [Name] [nvarchar](50) NOT NULL,

    CONSTRAINT [PK_Provinces] PRIMARY KEY CLUSTERED

    (

    [Id] ASC,

    [CountryId] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[Districts]  WITH CHECK ADD  CONSTRAINT [FK_Districts_Countries] FOREIGN KEY([CountryId])

    REFERENCES [dbo].[Countries] ([Id])

    ON UPDATE CASCADE

    GO

    ALTER TABLE [dbo].[Districts] CHECK CONSTRAINT [FK_Districts_Countries]

    GO

    ALTER TABLE [dbo].[Districts]  WITH CHECK ADD  CONSTRAINT [FK_Districts_Provinces] FOREIGN KEY([ProvinceId], [CountryId])

    REFERENCES [dbo].[Provinces] ([Id], [CountryId])

    ON UPDATE CASCADE

    GO

    ALTER TABLE [dbo].[Districts] CHECK CONSTRAINT [FK_Districts_Provinces]

    GO

    ALTER TABLE [dbo].[Provinces]  WITH CHECK ADD  CONSTRAINT [FK_Provinces_Countries] FOREIGN KEY([CountryId])

    REFERENCES [dbo].[Countries] ([Id])

    GO

    ALTER TABLE [dbo].[Provinces] CHECK CONSTRAINT [FK_Provinces_Countries]

    GO

  4. Alan Godfried says:

    After updating to 5.6.2, I have detected an anomaly.  Using a WCF Data Service operation that returns an IQueryable, when the IQueryable returns no records and ToList() is used, the exception "IQueryable returns no records causes Collection types are only supported in version 3.0 of the OData protocol and higher versions. They are not supported in version 1.0."  Since the data service is setup to use version 3.0, this message is incorrect.  Also, shouldn't ToList() just return a list with count of zero and not throw an exception?