I want to read records from an ENTITY where field VarCharDate is Between two user input dates. If I execute the sql directly it returns successfully all the records between two date.
i.e.
SELECT * FROM ENTITY WHERE VarCharDate BETWEEN '2010-09-01' AND '2012-08-01'
Here the VarCharDate field is of type VARCHAR that is predefined and I can't change it to DateTime. The Date Format is fixed to 'YYYY-MM-DD' for storing values in this field.
The Problem:
EDIT: I am using FluentNhibernate for Mapping entities. Also I build the schema on application startup by configuration.
I am using Nhibernate Linq for retrieving records in my C# application. I tried something like:
session.Query<ENTITY>()
.Where(e=>
Convert.ToDateTime(e.VarCharDate) >= Convert.ToDateTime(loInputDateString) &&
Convert.ToDateTime(e.VarCharDate) <= Convert.ToDateTime(hiInputDateString)
).ToList();
Executing above statement results in runtime error NotSupportedException.
Google shows result regarding ExtensionMethods and I found it all confusing so unable to implement it yet.
How could I achieve something like:
session.Query<ENTITY>(e=> e.VarCharDate.Between(loInputDateString,hiInputDateString)).ToList();
I also tried something mentioned in the link LINQ Between Operator
But it's not working though.