Supports non-deterministic/db-side-only methods in Linq

Description

Some methods are non-deterministic and should not be evaluated in the expression tree, once and for all resulting rows, but instead in the database. This is the case for Guid.NewGuid() and Random.Next().

Others may have distinct resulting values depending on the host on which they execute, and can change the query results depending on whether they are evaluated on db-client side or on db-server side. This is the case for DateTime.Now, DateTime.UtcNow, DateTimeOffset.Now, DateTimeOffset.UtcNow.

Currently they are always evaluated by NHibernate Linq provider before emitting the query with the resulting value as a parameter.

They should be left in the expression tree, and translated to appropriate HQL standard functions, then translated to corresponding database functions.

A user wishing to have them evaluated client side will then have to put their value in a variable then use that variable in its query.

By the way, for supporting this feature, when registering a method/property for the linq provider, we should be able to tell if it is partially evaluatable or not.

Environment

None

is related to

Activity

Show:

Alex Zaytsev May 8, 2018 at 9:59 PM

Moved here.

There are a few possible workarounds to get the previous behaviour back:

  • An option which disables the new behaviour globally.

  • A way to (re-)write a query. The suspect functions need to be turned to a parameter explicitly:

Frédéric Delaporte July 13, 2017 at 5:38 PM
Edited

If doing that, an option must be provided for reverting back to previous behavior. This change can be a major breaking changes, causing many working Linq queries to cease working.

DateTime.Now.WhateverUnRegisteredMethod() is currently working, due to it being evaluated and replaced by its returned value in the query. If DateTime.Now is no more evaluated but replaced by some sql getDate() function, it will then fail on trying to translate the unregistered method call on it.

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created July 12, 2017 at 2:53 PM
Updated May 8, 2018 at 10:01 PM
Who's Looking?