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?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With