Skip to content

Add Projections.Select in Criteria #2486

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

Merged
merged 2 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NHibernate/Criterion/Lambda/QueryOverProjectionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public QueryOverProjectionBuilder<T> SelectMin(Expression<Func<object>> expressi
/// </summary>
public QueryOverProjectionBuilder<T> Select(Expression<Func<T, object>> expression)
{
PushProjection(ExpressionProcessor.FindMemberProjection(expression.Body).AsProjection());
PushProjection(Projections.Select(expression));
return this;
}

Expand All @@ -186,7 +186,7 @@ public QueryOverProjectionBuilder<T> Select(Expression<Func<T, object>> expressi
/// </summary>
public QueryOverProjectionBuilder<T> Select(Expression<Func<object>> expression)
{
PushProjection(ExpressionProcessor.FindMemberProjection(expression.Body).AsProjection());
PushProjection(Projections.Select(expression));
return this;
}

Expand Down
16 changes: 16 additions & 0 deletions src/NHibernate/Criterion/Projections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,22 @@ public static string Concat(params string[] strings)
throw QueryOver.GetDirectUsageException();
}

/// <summary>
/// Projects given lambda expression
/// </summary>
public static IProjection Select(Expression<Func<object>> expression)
{
return ExpressionProcessor.FindMemberProjection(expression.Body).AsProjection();
}

/// <summary>
/// Projects given lambda expression
/// </summary>
public static IProjection Select<TEntity>(Expression<Func<TEntity, object>> expression)
{
return ExpressionProcessor.FindMemberProjection(expression.Body).AsProjection();
}

internal static IProjection ProcessConcat(MethodCallExpression methodCallExpression)
{
NewArrayExpression args = (NewArrayExpression)methodCallExpression.Arguments[0];
Expand Down
8 changes: 2 additions & 6 deletions src/NHibernate/Criterion/QueryOver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NHibernate.Loader;
using NHibernate.SqlCommand;
using NHibernate.Transform;
using NHibernate.Util;

namespace NHibernate.Criterion
{
Expand Down Expand Up @@ -404,12 +405,7 @@ public QueryOverRestrictionBuilder<TRoot,TSubType> WhereRestrictionOn(Expression

public QueryOver<TRoot,TSubType> Select(params Expression<Func<TRoot, object>>[] projections)
{
List<IProjection> projectionList = new List<IProjection>();

foreach (var projection in projections)
projectionList.Add(ExpressionProcessor.FindMemberProjection(projection.Body).AsProjection());

criteria.SetProjection(projectionList.ToArray());
criteria.SetProjection(projections.ToArray(x => Projections.Select(x)));
return this;
}

Expand Down