{
public int DepartmentId { get; set; }
public string DepartmentName { get; set; }
}
public class JobRole
public int JobRoleId { get; set; }
public string JobRoleName { get; set; }
public class Employee
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Department Departments { get; set; }
public List<JobRole> JobRoles { get; set; }
[DataServiceKeyAttribute("DepartmentId")]
public class Department
public static List<Department> GetDepartments()
List<Department> deptList = new List<Department>();
deptList.Add(new Department() { DepartmentId = 1, DepartmentName = "Information Technology" });
deptList.Add(new Department() { DepartmentId = 2, DepartmentName = "Finance" });
deptList.Add(new Department() { DepartmentId = 3, DepartmentName = "Human Resources" });
return deptList;
[DataServiceKeyAttribute("JobRoleId")]
public static List<JobRole> GetJobRoles()
List<JobRole> jobRoleList = new List<JobRole>();
jobRoleList.Add(new JobRole() { JobRoleId = 1, JobRoleName = "Software Engineer" });
jobRoleList.Add(new JobRole() { JobRoleId = 2, JobRoleName = "Project Manager" });
jobRoleList.Add(new JobRole() { JobRoleId = 3, JobRoleName = "Accountant" });
jobRoleList.Add(new JobRole() { JobRoleId = 4, JobRoleName = "HR Executive" });
return jobRoleList;
[DataServiceKeyAttribute("EmployeeId")]
public static List<Employee> GetEmployees()
List<Employee> empList = new List<Employee>();
empList.Add(new Employee()
EmployeeId = 1,
FirstName = "Jaliya",
LastName = "Udagedara",
Departments = Department.GetDepartments().First(dept => dept.DepartmentName == "Information Technology"),
JobRoles = new List<JobRole>()
JobRole.GetJobRoles().First(jobRole => jobRole.JobRoleName == "Software Engineer"),
JobRole.GetJobRoles().First(jobRole => jobRole.JobRoleName == "Project Manager")
});
EmployeeId = 2,
FirstName = "John",
LastName = "Doe",
Departments = Department.GetDepartments().First(dept => dept.DepartmentName == "Finance"),
JobRole.GetJobRoles().First(jobRole => jobRole.JobRoleName == "Accountant")
EmployeeId = 3,
FirstName = "Jane",
Departments = Department.GetDepartments().First(dept => dept.DepartmentName == "Human Resources"),
JobRole.GetJobRoles().First(jobRole => jobRole.JobRoleName == "HR Executive")
return empList;
public class MyDataContext
public IQueryable<Employee> Employees
get
return Employee.GetEmployees().AsQueryable();
public IQueryable<Department> Departments
return Department.GetDepartments().AsQueryable();
public IQueryable<JobRole> JobRoles
return JobRole.GetJobRoles().AsQueryable();
using System.Data.Services;
using System.Data.Services.Common;
namespace WCFDataServicesWithReflectionProvider
public class WcfDataService1 : DataService<MyDataContext>
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
http://domain/service.svc/$metadata