It seems that the nhibernate Linq provider did not implement LastOrDefault() - as a result, it is not supported. You can get around this by first setting an order that will return the elements you need in the reverse order, and then use FirstOrDefault() instead:
var q = SessionInstance.Query<EnterAndExitArchive>() .OrderByDescending(x=> x.SomeOrderField) .FirstOrDefault<EnterAndExitArchive>(x => x.Archive.Id == archiveId);
I also see that you are not currently ordering your results in your query at all - in what order did you expect the results to be? If the order of undefined LastOrDefault() matches FirstOrDefault() ; -)
source share