-
Notifications
You must be signed in to change notification settings - Fork 934
Fix QueryOver Coalesce projection in Select #2246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NHibernate.Dialect.Function; | ||
using NHibernate.Engine; | ||
using NHibernate.SqlCommand; | ||
using NHibernate.Type; | ||
using NHibernate.Util; | ||
|
||
namespace NHibernate.Criterion | ||
{ | ||
|
@@ -16,6 +15,7 @@ public class SqlFunctionProjection : SimpleProjection | |
private readonly ISQLFunction function; | ||
private readonly string functionName; | ||
private readonly IType returnType; | ||
private readonly IProjection returnTypeProjection; | ||
|
||
public SqlFunctionProjection(string functionName, IType returnType, params IProjection[] args) | ||
{ | ||
|
@@ -31,6 +31,13 @@ public SqlFunctionProjection(ISQLFunction function, IType returnType, params IPr | |
this.args = args; | ||
} | ||
|
||
public SqlFunctionProjection(string functionName, IProjection returnTypeProjection, params IProjection[] args) | ||
{ | ||
this.functionName = functionName; | ||
this.returnTypeProjection = returnTypeProjection; | ||
this.args = args; | ||
} | ||
|
||
public override bool IsAggregate | ||
{ | ||
get { return false; } | ||
|
@@ -107,10 +114,18 @@ private static SqlString GetProjectionArgument(ICriteriaQuery criteriaQuery, ICr | |
} | ||
|
||
public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery) | ||
{ | ||
var type = GetReturnType(criteria, criteriaQuery); | ||
return type != null ? new[] {type} : Array.Empty<IType>(); | ||
} | ||
|
||
private IType GetReturnType(ICriteria criteria, ICriteriaQuery criteriaQuery) | ||
{ | ||
ISQLFunction sqlFunction = GetFunction(criteriaQuery); | ||
IType type = sqlFunction.ReturnType(returnType, criteriaQuery.Factory); | ||
return new IType[] {type}; | ||
|
||
var resultType = returnType ?? returnTypeProjection?.GetTypes(criteria, criteriaQuery).FirstOrDefault(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are more than one type returned, should it be silently ignored? (Shouldn't And all the null coalesce, OrDefault stuff combined with yielding an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well I don't know. I made it the way I saw somewhere else in Criteria handling. IMHO it's not important until multi-column support is added to
Not sure I properly understand it. But this logic ends up in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The trouble is, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No but empty type collection also doesn't make much sense for using in Select projection... Ok - I've added null handling just in case. |
||
|
||
return sqlFunction.ReturnType(resultType, criteriaQuery.Factory); | ||
} | ||
|
||
public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other option is to use
GuessType
here but current fix looks more proper to me (though it requires changes inSqlFunctionProjection
). Let me know if you thinkGuessType
is enough here.