public dynamic CriteriaToLinq(ApiReportCriteria criteria) // using system.linq.dynamic.Library { var qry = _dbContext.Departments.Join(_dbContext.Employees, d => d.Id, e => e.DepartmentId, (d, e) => new { department = d.Name, emp = e.Name }).Where("Id=1").OrderBy("Name"); //.Select("new (Id , Name)"); // anonymus type to dynamic return(qry.ToDynamicArray()); }
public async Task <ApiResponse <dynamic> > GetReports([FromBody] ApiReportCriteria testReportCriteria) { var response = new ApiResponse <dynamic>(); var departments = _reportManager.CriteriaToLinq(testReportCriteria); // departments = new List<Department>() {new Department() {Id=100, Name = "depart100"} , new Department() { Id = 200, Name = "depart200" } }; response.Data = departments; response.ReportCriteria = testReportCriteria; response.RequestInfo.Controller = this.Request.Headers["referer"]; return(response); }