using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace Wcfdataserviceconsole { public class Employee { public int id { get; set; } public string name { get; set; } public Employee() { } } public class EmployeeDetails { public string ConnectionString = "Data Source=(local);Initial Catalog=Employee;Integrated Security=True"; public SqlConnection Con =null; public List<Employee> Implementation() { List<Employee> employee= new List<Employee>(); Con = new SqlConnection(ConnectionString); Con.Open(); string str = "select * from Employee"; SqlCommand Cmd = new SqlCommand(str, Con); SqlDataReader sqlDataReader = Cmd.ExecuteReader(); while (sqlDataReader.Read()) { Employee emp = new Employee(); emp.id = sqlDataReader.GetInt32(0); emp.name = sqlDataReader.GetString(1); employee.Add(emp); } return employee; } public IQueryable<Employee> EmployeeContext { get { return new EmployeeDetails().Implementation().AsQueryable(); } } } }
using System; using System.Collections.Generic; using System.Data.Services; using System.Data.Services.Common; using System.Linq; using System.ServiceModel.Web; using System.Web; namespace WcfDataService2 { public class OdataCustomDataService : DataService<MyCustomDataSource> { // 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("GetEmployeeByName", ServiceOperationRights.All); // config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)