You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When querying a data model that contains a DateOnly property, where I want to group by that property to get summary or just the distinct records, I get an error saying that the object reference not set to an instance of an object. When I change this to use DateTime the problem doesn't exist. Currently using DateOnly as EF 8 now supports DateOnly (date database field).
Project Code To Reproduce
using Microsoft.AspNetCore.OData;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using Microsoft.OData.ModelBuilder;
var builder = WebApplication.CreateBuilder(args);
var modelBuilder = new ODataConventionModelBuilder();
var timeRecord = modelBuilder.EntitySet<TimeRecord>(nameof(TimeRecord)).EntityType;
timeRecord.Select().Expand(6).OrderBy().Filter().Count().Page();
// DI
builder.Services
.AddControllers()
.AddOData(options => options.EnableQueryFeatures(1000).AddRouteComponents(modelBuilder.GetEdmModel()));
// Configure
var app = builder.Build();
app.UseRouting();
app.UseEndpoints(endpoints => { endpoints.MapControllers();});
app.Run();
public class TimeRecord
{
public long Id { get; set; }
public DateOnly PeriodDate { get; set; }
public decimal Hours { get; set; }
public string Employee { get; set; }
}
public class TimeRecordController : ODataController
{
[EnableQuery]
public IQueryable Get()
{
return (new List<TimeRecord>()
{
new TimeRecord(){Id = 1, Employee = "John", PeriodDate = DateOnly.Parse("2024-10-01"), Hours = 35},
new TimeRecord(){Id = 2, Employee = "John", PeriodDate = DateOnly.Parse("2024-10-08"), Hours = 15},
new TimeRecord(){Id = 3, Employee = "Ellen", PeriodDate = DateOnly.Parse("2024-10-08"), Hours = 25},
new TimeRecord(){Id = 4, Employee = "John", PeriodDate = DateOnly.Parse("2024-10-15"), Hours = 30},
new TimeRecord(){Id = 5, Employee = "John", PeriodDate = DateOnly.Parse("2024-10-22"), Hours = 27},
}).AsQueryable();
}
}
Expected behavior
The expected behavior would be an odata list of the groupby property in this case: [ { "PeriodDate": "2024-10-01" }, { "PeriodDate": "2024-10-08" }, { "PeriodDate": "2024-10-15" }, { "PeriodDate": "2024-10-22" } ]
Screenshots
Additional context
Making the following change to ExpressionBinderBase, solves the problem listed above.
The text was updated successfully, but these errors were encountered:
Assemblies affected
ASP.NET Core OData 9.x
Describe the bug
When querying a data model that contains a DateOnly property, where I want to group by that property to get summary or just the distinct records, I get an error saying that the object reference not set to an instance of an object. When I change this to use DateTime the problem doesn't exist. Currently using DateOnly as EF 8 now supports DateOnly (date database field).
Project Code To Reproduce
Request
.../TimeRecord?$apply=groupby((periodDate))
Expected behavior
The expected behavior would be an odata list of the groupby property in this case:
[ { "PeriodDate": "2024-10-01" }, { "PeriodDate": "2024-10-08" }, { "PeriodDate": "2024-10-15" }, { "PeriodDate": "2024-10-22" } ]
Screenshots
Additional context
Making the following change to ExpressionBinderBase, solves the problem listed above.
The text was updated successfully, but these errors were encountered: