views:

156

answers:

1

Hi,

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

+1  A: 

Generic invariance is causing you problems, basically. A Func<object, bool> isn't convertible to a Func<Case,bool> - at least not until .NET 4.0

Note that Queryable.Where will 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 of Expression<Func<Object,bool>>? If you can, that should make it work.

Jon Skeet
I did kinda wonder about that. Can't find any evidence of IronPython supporting expression trees, so I've switched to using HQL instead of Linq. Cheers.
littlecharva