Hi,
I am trying to retrieve items in DB, based on a criteria:
(aDateTime + aTimeSpan) >= anotherDateTime
It works fine, except that only the [year-month-day] of the DateTimes are taken into account. For instance, if (aDateTime + aTimeSpan) is at time 1am and anotherDateTime is at time 2am on the same day, then the above expression is evaluated to true, when I think it should be evaluated to false.
I have checked what is the generated SQL query, and actually the parameter types is "Date" so that's probably why the time of the days are ignored. Could you please indicate a way to write the Linq filter so that the SQL query uses DateTimes?
Here is my current Linq filter code:
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.ProjectSchemaNameToUse = study.TimePoint.Subject.ProjectSite.Project.SchemaName;
IPathEdge[] path = PathFactories.PathFactoryTimeFrame.WithDefault();
LinqMetaData metaData = new LinqMetaData(adapter);
Expression<System.Func<TimeFrameEntity, bool>> filter = PredicateBuilder.Null<TimeFrameEntity>();
filter = filter.And(e => (e.RefTimePointTypeId == study.TimePoint.TimePointType.ID));
filter = filter.And(e => (e.ModalityId == study.Modality.ID));
filter = filter.And(e => (((DateTime)(study.StudyDate.Value + e.StartRange)) >= ((DateTime)minimumStartDate)));
filter = filter.And(e => (((DateTime)(study.StudyDate.Value + e.StartRange)) <= ((DateTime)maximumStartDate)));
IQueryable<TimeFrameEntity> entities = (
from e in metaData.TimeFrame.Where(filter).WithPath(path)
select e);
var collection = ((ILLBLGenProQuery)entities).Execute<EntityCollection<TimeFrameEntity>>();
And here is the generated SQL query. Note that on the last 4 lines, the parameter types is "Date" which I think is my problem. I don't know why the type is "Date" and not "DateTime" or "TimeStamp"
Generated Sql query:
Query: SELECT "LPLA_1"."TimeFrameID" AS "TimeFrameId", "LPLA_1"."TimePointTypeID" AS "TimePointTypeId", "LPLA_1"."RefTimePointTypeID" AS "RefTimePointTypeId", "LPLA_1"."ModalityID" AS "ModalityId", "LPLA_1"."StartRange", "LPLA_1"."Duration", "LPLA_1"."GracePeriod" FROM "teststudy"."TimeFrame" "LPLA_1" WHERE ( ( ( ( ( ( ( ( ( "LPLA_1"."RefTimePointTypeID" = :RefTimePointTypeId1) AND ( "LPLA_1"."ModalityID" = :ModalityId2)) AND ( :LLBLEP4 + "LPLA_1"."StartRange" >= :LPFA_13)) AND ( :LLBLEP6 + "LPLA_1"."StartRange" <= :LPFA_25)))))))
Parameter: :RefTimePointTypeId1 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 2.
Parameter: :ModalityId2 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.
Parameter: :LLBLEP4 : Date. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 12/10/2009 4:15:00 PM.
Parameter: :LPFA_13 : Date. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 12/14/2009 4:19:49 PM.
Parameter: :LLBLEP6 : Date. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 12/10/2009 4:15:00 PM.
Parameter: :LPFA_25 : Date. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 12/15/2009 4:19:49 PM.
And last, here is the TimeFrameEntity.StartRange property definition in the LLBLgen generated entity:
/// <summary> The StartRange property of the Entity TimeFrame<br/><br/>
/// </summary>
/// <remarks>Mapped on table field: "TimeFrame"."StartRange"<br/>
/// Table field type characteristics (type, precision, scale, length): Interval, 0, 0, 0<br/>
/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
public virtual System.TimeSpan StartRange
{
get { return (System.TimeSpan)GetValue((int)TimeFrameFieldIndex.StartRange, true); }
set { SetValue((int)TimeFrameFieldIndex.StartRange, value); }
}
The Database is PostgreSql.
Thanks in advance for your help,
Yves.