Sunday, March 20, 2011

Full Linq Query Instead of Lambdas with Fluent-NHibernate?

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()
From stackoverflow

0 comments:

Post a Comment