views:

1646

answers:

1

I'm trying to use Fluent-NHibernate's Query method which looks like this:

public T[] Query<T>(Expression<System.Func<T, bool>> where)
        {
            return _session.Linq<T>().Where(where).ToArray();
        }

I'm using VB, so to send it a lambda expression I can call it with a line like this:

Dim products = flRepos.Query(Of Product)(Function(p As Product) p.Id > 5)

This syntax is correct, but there is a problem with Fluent's underlying use of Linq to Nhibernate that breaks when using VB lambda expressions.

I'm fine with not using lambda expressions, I just don't have a clue how I would rewrite that line to not use a lambda.

For reference, using full linq queries in VB does work with Linq 2 Nhibernate. This query worked fine for me:

Dim product = (From p In session.Linq(Of Product)() _ 
                        Where p.Id = testId _ 
                        Select p).FirstOrDefault()
+1  A: 

There are a lot of quirks to the current NHibernate LINQ model, unfortunately these won't be really resolved until NHibernate 2.1 is released. There are changes needed to the NHibernate core to really support it fully, so instead of a contrib it will be a full/integrated part of the 2.1 release. Ayende has a blog update posted a few months ago outlining the current caveats/plans.

Nick Craver