Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The LastResultOperator result operator is not current supported

I have a query using linq to NHibernate, for EnterAndExitArchive entity. This entity has a association by Archive entity.

public EnterAndExitArchive GetLastEnterAndExitArchive(long archiveId)
{
   var q = SessionInstance.Query<EnterAndExitArchive>()
          .Where(x => x.Archive.Id == archiveId)
          .LastOrDefault<EnterAndExitArchive>();

   return q;
}

Or

public EnterAndExitArchive GetLastEnterAndExitArchive(long archiveId)
{
   var q = SessionInstance.Query<EnterAndExitArchive>()
          .LastOrDefault<EnterAndExitArchive>(x => x.Archive.Id == archiveId);

   return q;
}

But this has a runtime error. Message of exception is The LastResultOperator result operator is not current supported.

Why?

like image 601
Ehsan Avatar asked Dec 05 '22 18:12

Ehsan


1 Answers

LastOrDefault() is not supported in NHibernate.

Maybe you could order the result and use FirstOrDefault() instead:

public EnterAndExitArchive GetLastEnterAndExitArchive(long archiveId)
{
   var q = SessionInstance.Query<EnterAndExitArchive>()
          .Where(x => x.Archive.Id == archiveId)
          .OrderByDescending(x => x.Something)
          .FirstOrDefault();

   return q;
}
like image 116
dillenmeister Avatar answered Jan 06 '23 10:01

dillenmeister