Click here to Skip to main content
15,889,116 members
Articles / Programming Languages / C#

Advanced using OData in .NET: WCF Data Services

Rate me:
Please Sign up or sign in to vote.
4.88/5 (26 votes)
16 Dec 2010Ms-PL9 min read 227.4K   6.2K   88  
Samples showcasing usage of OData in .NET (WCF Data Services); samples go in increasing order of complexity, addressing more and more advanced scenarios.
using System;
using System.Collections.Generic;
using System.Linq;

namespace ExposingTransformation
{
	/// <summary>Represents a data model exposing both the employee and the department.</summary>
	public class DataModel : IDisposable
	{
		private readonly ODataDemoEntities _dbContext = new ODataDemoEntities();

		/// <summary>Default constructor.</summary>
		/// <remarks>Populates the model.</remarks>
		public DataModel()
		{
			Departments = from d in _dbContext.Department
						  select new DepartmentModel
						  {
							  ID = d.DepartmentID,
							  Name = d.DepartmentName
						  };

			Employees = from e in _dbContext.Employee
						select new EmployeeModel
						{
							ID = e.EmployeeID,
							DepartmentID = e.DepartmentID,
							AddressID = e.AddressID,
							FirstName = e.FirstName,
							LastName = e.LastName,
							StreetNumber = e.Address.StreetNumber,
							StreetName = e.Address.StreetName
						};
		}

		/// <summary>Returns the list of employees.</summary>
		public IQueryable<EmployeeModel> Employees { get; private set; }

		/// <summary>Returns the list of departments.</summary>
		public IQueryable<DepartmentModel> Departments { get; private set; }

		void IDisposable.Dispose()
		{
			_dbContext.Dispose();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect CGI
Canada Canada
Vincent-Philippe is a Senior Solution Architect working in Montreal (Quebec, Canada).

His main interests are Windows Azure, .NET Enterprise suite (e.g. SharePoint 2013, Biztalk Server 2010) & the new .NET 4.5 platforms.

Comments and Discussions