Comparing dates in string, using SQLite and NHibernate

0

I'm using SQLite and NHIbernate, and I'm saving my Datas as String in SQLite because I can not store dates on it. Everything was going ok, but I had to compare dates to print a report. Now, I can not make this comparison because it is in string , and I can not convert to Date in LINQ / Lambda.

I've tried the following:

var dataInicial = DateTime.Parse(_DataInicial);
var dataFinal = DateTime.Parse(_DataFinal);
return session.QueryOver<Locacoes>()
     .Where(c => DateTime.Parse(c.DataInicial) >= dataInicial )
     .Where(c => DateTime.Parse(c.DataFinal) <= dataFinal).List();

But a Exception in the first Where :

  

"Locale variable 'c' is referenced in scope '' but not defined".

I do not know if this is the problem, but I'd really like to compare two dates in NHibernate, since they are in string because they are written in SQLite.

    
asked by anonymous 04.11.2016 / 13:39

1 answer

0

Thanks for everyone's help, but I had to modify the search method.

I'm going to have to change the format of my date as it was on "07/31/2016" to "20160731".

and it looks like this:

            string dataInicial = "'20100604'";
            var query = "SELECT * from Clientes as c where c.Data >= " + dataInicial;
            var lista = session.CreateSQLQuery(query).List();
    
04.11.2016 / 16:04