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?
Are you certain that OrderByDescending(msh => msh.CreateTime).FirstOrDefault()
Is not returning null for any elements in your repository? That bit of code seems to me to be the bit in question.
(...OrderByDescending(msh => msh.CreateTime).FirstOrDefault() ?? someDummyStatusNotSatisfyingClause)
Might solve your problem.
Another possibility is that you haven't instructed NHibernate how/when to materialiaze the status histories in the entity definition. My experience with NHibernate is that some query like you are attempting might be better suited as a repository function (a stored procedure)
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