Comparing Dates in string, using Sqlite and Nhibernate

Asked

Viewed 231 times

0

I am using Sqlite and Nhibernate, and I am saving in my bank the Datas as String in Sqlite, as it is not possible to store dates in it. Everything was going ok, but I needed to compare dates to print out a report. Now, I can’t make that comparison, because it’s in string, and I can’t convert to Date in LINQ/Lambda.

I 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 of the one Exception in the first Where:

"The 'c' variable of the'Locations' type is referenced in the 'scope, but not defined".

I don’t know if that’s the problem, but I’d really like how I can compare two dates on Nhibernate, being that they’re on string because recorded in Sqlite.

1 answer

0


Thanks for all your help, but I had to modify the search method.

I will have to change the format of my date as it was in "31/07/2016" to "20160731".

and stayed that way:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.