AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Added support for TimeZoneInfo configuration on ODataQuerySettings #112

Closed andy-clymer closed 2 years ago

andy-clymer commented 2 years ago

Thanks for this making this project. It has made working with OData and DTOs incredibly simple.

While testing an OData filter expression using datetime, I discovered an issue with the generated expression used to query the database. I found the issue/fix being discussed on the AspNetCoreOData repo: #268 and have made the necessary changes to resolve the problem.

Brief explanation of issue:

  1. Microsoft SQL Database stores datetime as UTC in datetime2(7): 2021-09-08 00:00:00.0000000
  2. Make OData request with filter using UTC time: $filter=dateTime eq 2021-09-08T00:00:00Z
  3. ASP.NET Core API running in time zone EST processes request generating where clause: WHERE date_time = '2020-09-07T20:00:00.0000000'
  4. No records match that date and time and response conatins no records.

Fix: When using ApplyTo() for building the filter expression, pass in the TimeZoneInfo the server should use to parse the datetime.

BlaiseD commented 2 years ago

Thanks.

Please and two tests each (two different time zones) to GetQueryTests and GetTests showing the expected outcomes (OpsTenant has a DateTime property).

andy-clymer commented 2 years ago

Sorry about that. For some reason I didn't include my tests in the original PR. I updated them according to your message and are pending your approval.