[Route("[controller]/[action]")]
[ApiController]
public class PatientsController : ODataController
// public class PatientsController : ControllerBase
{
private readonly DataContext _dataContext;
private readonly IMapper _mapper;
public PatientsController(DataContext dataContext, IMapper mapper)
{
_mapper = mapper;
_dataContext = dataContext;
}
public PageResult<WebApplication1.ViewModels.Patients> GetPage(ODataQueryOptions<WebApplication1.Models.PatientsView> options)
{
IQueryable<WebApplication1.Models.PatientsView> result = _dataContext.PatientsView;
if (options?.Filter != null)
result = options.Filter.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;
int count = result.Count();
if (options?.OrderBy != null)
result = options.OrderBy.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;
if (options?.Skip != null)
result = options.Skip.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;
if (options?.Top != null)
result = options.Top.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;
IEnumerable<WebApplication1.ViewModels.Patients> patientsDto = _mapper.Map<IEnumerable<WebApplication1.ViewModels.Patients>>(result.ToList());
return new PageResult<WebApplication1.ViewModels.Patients>(patientsDto as IEnumerable<WebApplication1.ViewModels.Patients>, null, count);
}
and my grid is defined as following:
<div class="form-group row">
<ej-grid id="GridPatients" row-data-bound="provascript">
<e-datamanager id="patientDataManager" url="/Patients/GetPage" adaptor="ODataV4Adaptor"></e-datamanager>
<e-page-settings enable-templates="false" show-defaults="true" page-size="5"></e-page-settings>
<e-sort-settings>
<e-sorted-columns>
<e-sorted-column field="LastName" direction="Ascending"></e-sorted-column>
<e-sorted-column field="FirstName" direction="Ascending"></e-sorted-column>
</e-sorted-columns>
</e-sort-settings>
<e-columns>
<e-column field="Id" visible="false"></e-column>
<e-column field="TitleAbbr" header-text="Title" header-text-align="TextAlign.Center" text-align="Center" width="60"></e-column>
<e-column field="FirstName" header-text="First Name" header-text-align="TextAlign.Center" text-align="Center" width="100"></e-column>
<e-column field="LastName" header-text="Last Name" header-text-align="TextAlign.Center" text-align="Center" width="100"></e-column>
<e-column field="BirthDate" header-text="Birth Date" header-text-align="TextAlign.Center" text-align="Center" width="60"
edit-type="Datepicker" format="{0:dd/MM/yyyy}"></e-column>
</e-columns>
</ej-grid>
</div>
When i switch from the ODataV4 to WebApi the result is good.
Thanks in advance
Stefano Capobianco