Вопрос

I've written an application that uses LINQ to NHibernate for it's database queries. Code in my domain layer creates expressions of type

System.Linq.Expressions.Expression<Func<T, bool>>

These are passed to repositories in my data access layer, which then use them like this:

return session.Query<T>.Where(expression)...

This was all great before I discovered that NHibernate LINQ provider completely ignores the option fetch="join" in mapping files, meaning that objects are fetched using several select statements rather than a single select with joins.

So I'm trying to move over to the QueryOver API, which fully supports joins. I immediately ran into the problem that methods like string.Equals are not supported. I also have several custom extension methods which I use in my expressions, for which I have added support for in LINQ to NHibernate by extending BaseHqlGeneratorForMethod.

How can I add support for these methods in the QueryOver API? I can't find any information on this.

I'm aware you can do things like this:

Session.QueryOver<T>().WhereRestrictionOn(x=>x.Foo).IsInsensitiveLike("bar")

but I'm looking for a way to do everything using the same expressions that I was using before with LINQ to NHibernate.

Это было полезно?

Решение

The answer seems to be that it's not possible to use lambda expressions with the QueryOver API. As Oskar pointed out in a comment to the question, only very simple lambda expressions are supported. I'm rewriting my code so that the repository methods receive query objects rather than lambda expressions.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top