-2

I have an ISession.Queryover code block. In where clause, there is a problem as shown below

var receipts= ISession.QueryOver(() => receipt)
    .Where(Restrictions.Le(
                Projections.Property(() => receipt.SentDate), 
                receipt.LastDate), 
           null) //object references to null

In general I have a table called receipt and I am trying to get datas in case their LastDate is equal to their SentDate. I guess it is because I used same object for comparing.

I need to compare those 2 property which belong to same entity.How can I fix this issue?

Samuel
  • 3
  • 3
  • Can you add a little more of the code, to explain exactly what you are trying to achieve? – Kjartan Feb 02 '22 at 06:20
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) –  Feb 02 '22 at 06:37
  • @MickyD unfortunately no :/ – Samuel Feb 02 '22 at 06:45
  • Us there a reason you don’t use the query syntax which is regular LINQ? `var receipts = session.Query().Where(x => receipt.SentDate <= x.LastDate)` with `` being the type you want to query. – ckuri Feb 02 '22 at 08:31
  • yes @ckuri, after implementing this, it worked! – Samuel Feb 02 '22 at 08:36

1 Answers1

0

Seems to me like you're using a mix of two different types of syntax.

Perhaps you can use something like this instead:

var receipts = 
      ISession.QueryOver(() => receipt)
              .Where(x => x.LastDate >= x.SentDate)
Kjartan
  • 18,591
  • 15
  • 71
  • 96
  • 1
    .Where(x => x.LastDate >= x.SentDate) this line fixed the problem! Thanks for helping :) Can you add this line to your answer? I will accept it and meybe some other people can get help from this – Samuel Feb 02 '22 at 08:32
  • Ah, that's even shorter and better. :) Glad it put you on the right track. I've updated my answer, as you suggested. – Kjartan Feb 02 '22 at 08:47