All our code works locally on our computers (Tested on 8+ machines and also in new Docker Container). As soon as we deploy it to Azure, we keep getting the following error every time we're trying to fetch any data which contains dates.
Exception which is thrown:
Can't write CLR type NodaTime.LocalDateTime with handler type TimestampHandler
The column have the type of timestamp in the database, which we need to be able to store it as localdatetime.
Server Stats:
- Linux
- .NET 7.0
Code examples:
The below code is to ensure mapping for NodaTime dates.
db.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"), opt => {
opt.UseNodaTime();
});
An example of retrieving the data, where the exception is thrown:
public async Task<List<Booking>> GetBookings(LocalDate from, LocalDate to) {
var fromDate = new LocalDateTime().FromLocalDateAndLocalTime(from, LocalTime.MinValue);
var toDate = new LocalDateTime().FromLocalDateAndLocalTime(from, LocalTime.MaxValue);
var bookings = _db.Rentals
.Include(r => r.Product)
.Where(r => r.Status != RentalStatus.Rejected)
.Where(r => (r.PickupAt >= fromDate &&
r.PickupAt <= toDate ||
(r.ReturnAt >= fromDate &&
r.ReturnAt <= toDate)))
.Select(r => new Booking() {
Product = r.Product!,
Rental = r,
From = r.PickupAt,
To = r.ReturnAt
});
return await bookings.ToListAsync();
}
Again, everything works until we deploy it. So we hope someone have suggestion about, what it could be. All other API calls are working as intended, it's only when it comes to this Date retrieval. If we spin it up locally and use the exact same database, it doesn't throw the Exception.
We're using PostgreSQL 14.6 as database.
We've been following the documentation from: https://www.npgsql.org/doc/types/nodatime.html?tabs=datasource

