|
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.
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.