'SqlException: Operand type clash: time is incompatible with bigint

I'm trying to use NHibernate Session Criteria with TimeSpan comparison and getting this exception.

In other words, I have this:

TimeSpan timeNow = DateTime.Now.TimeOfDay;

...

criteria.Add(Restrictions.Where<Schedule>(s => timeNow >= s.StartTime));

var result = criteria.List<Schedule>(); // <-- Throws the exception

...

I checked the SQL Profiler to see the generated query, and I noticed that the value of timeNow converted into something like 438893700286.

Here is the mapping of this field:

[Property(Column = "[Start_Time]", Type ="TimeAsTimeSpan", NotNull = false)]
public TimeSpan? StartTime { get; set; }

And everything works fine if I don't try to compare the value of this field in the query.

I mean, I can fetch all the schedules from the DB, and then compare the value in the code, but the idea is to do it in the query.

So, what should I change to make it work?

I tried changing TimeAsTimeSpan to Time or providing the type as typeof(TimeAsTimeSpanType). Nothing helps.

BTW, I use .Net Framework 4.8



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source