I am working on a pure code first implementation of Hot Chocolate (v12.15.2) and .NET 6. I have filtering on all my string and number fields working as expected. However, with the date fields, I can only do greater than or less than. Doing a date equal to date does not return anything.
[Authorize]
[UseOffsetPaging(MaxPageSize = 50000, IncludeTotalCount = true)]
[UseFiltering]
[UseSorting]
public IQueryable<ActiveUser> GetActiveUserOffset(
[Service] IActiveUserService service)
{
return service.GetActiveUsers();
}
And here is the class ActiveUser
{
[Key]
[Column("user_id")]
public int UserId { get; set; }
[Column("user_name")]
public string? UserName { get; set; }
[Column("join_dt")]
[GraphQLType(typeof(DateTime))]
public DateTime? JoinDate {get; set;}
}
Any suggestions on how to get the date equal to work would be great.
CodePudding user response:
Looks like you've got a type mismatch if you're trying to compare a date and a DateTime:
public DateTime? JoinDate {get; set;}
Even DateTime
s which are initialised with only a date will contain a time component:
var myDateTime = new DateTime(2022, 11, 16);
Console.WriteLine(myDateTime.ToString());
// Outputs 16/11/2022 12:00:00 am
The issue is if you try to perform an eq
on a JoinDate
which is "2022-11-16 08:00"
with a passed date of "2022-11-16"
, the date you're passing in is converted to a DateTime
of "2022-11-16 00:00"
.
Then you're comparing "2022-11-16 08:00"
with "2022-11-16 00:00"
, which are not equal.