I’m trying to extend my webapp with IronPython, which is working wonderfully so far, but I can’t seem to get it to play nicely with my NHibernateLinq setup.
I’m making an IQueryable<Case> available to the IronPython code, and then I’m using the Linq methods to filter it down, such as:
Enumerable.Where[object](data, Func[object, bool](func))
This works fine, but because I’m using Enumerable instead of Queryable, it’s pulling back ALL the records from the database, before running the Where function on them, when I want the Where clause to be added to the SQL query generated by NHibernate.
So I tried:
Queryable.Where[object](data, Func[object, bool](func))
But that simply yields:
Microsoft.Scripting.ArgumentTypeException: expected IQueryable[object], got Query[Case]
Am I missing something? Is this even possible?
Anthony
Generic invariance is causing you problems, basically. A
Func<object, bool>isn’t convertible to aFunc<Case,bool>– at least not until .NET 4.0Note that
Queryable.Wherewill require an expression tree, not a delegate. Does IronPython support expression trees?If you can produce an expression tree in Python, can you make it
Expression<Func<Case,bool>>instead ofExpression<Func<Object,bool>>? If you can, that should make it work.