Antlr exception with message "plan b" when walking IQueryable of NHibernate entities

Viewed 778

I've got quite weird exception when trying to materialize the IQueryable I got form NHibernate.Linq. The exception of type Antlr.Runtime.Tree.RewriteEmptyStreamException just states plan b, and nothing more. Detailed exception can be found at http://pastebin.com/kR2dvDHd

Here's the code that throws an exception:

var matterExtractor = new MatterExtractor();
var InactiveMatters = matterExtractor.GetMattersAtStatus(General.InactiveMatterStatus);
Assert.IsNotNull(InactiveMatters); //OK
Assert.IsInstanceOfType(InactiveMatters, typeof (IQueryable<Matter>)); // OK
var MaterializedMatters = InactiveMatters.ToList(); //Exception is thrown

Matter Extractor class is as simple as follwing:

public class MatterExtractor
{
    public virtual IQueryable<Matter> GetMattersAtStatus(MatterStatus status)
    {
        return
            (new NHibernateRepository.Repository<Matter>()).Where(
                m => m.MatterStatusHistories.OrderByDescending(msh => msh.CreateTime).FirstOrDefault().MatterStatus == status);
    }
}

NHibernateRepository.Repository<T> is an utility class that implements IQueryable via NHibernate.LINQ extension methods to NHibernate.Session. Nothing specific here, but just in case, here's the listing: http://pastebin.com/MgDxDg3Y

I don't think it's related to NHibernate mappings, since other tests that interact with Matter entity run just fine. Most probably it's related to the Where clause, but I can't understand what's going wrong with that clause. I've tried replacing

OrderByDescending(msh => msh.CreateTime).FirstOrDefault()

to

OrderBy(msh => msh.CreateTime).LastOrDefault()

but it just told me The LastResultOperator result operator is not current supported, so I think NHibernate.Linq just can't stay LastOrDefault.

Any ideas what does plan b mean and how can I workaround it?

1 Answers
Related