|
|
@ -3,44 +3,67 @@ using Connected.Expressions.Formatters;
|
|
|
|
using Connected.Expressions.Translation;
|
|
|
|
using Connected.Expressions.Translation;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
using System.Runtime.ExceptionServices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Connected.Expressions;
|
|
|
|
namespace Connected.Expressions;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class SelectExpression : AliasedExpression
|
|
|
|
public sealed class SelectExpression : AliasedExpression
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public SelectExpression(Alias alias, IEnumerable<ColumnDeclaration> columns, Expression from, Expression? where,
|
|
|
|
public SelectExpression(Alias alias, IEnumerable<ColumnDeclaration> columns, Expression from, Expression? where,
|
|
|
|
IEnumerable<OrderExpression>? orderBy, IEnumerable<Expression>? groupBy, bool isDistinct, Expression? skip, Expression? take, bool isReverse)
|
|
|
|
IEnumerable<OrderExpression>? orderBy, IEnumerable<Expression>? groupBy, bool isDistinct, Expression? skip, Expression? take, bool isReverse)
|
|
|
|
: base(DatabaseExpressionType.Select, typeof(void), alias)
|
|
|
|
: base(DatabaseExpressionType.Select, typeof(void), alias)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Columns = columns.ToReadOnly();
|
|
|
|
Columns = columns.ToReadOnly();
|
|
|
|
IsDistinct = isDistinct;
|
|
|
|
IsDistinct = isDistinct;
|
|
|
|
From = from;
|
|
|
|
From = from;
|
|
|
|
Where = where;
|
|
|
|
Where = where;
|
|
|
|
OrderBy = orderBy?.ToReadOnly();
|
|
|
|
OrderBy = orderBy?.ToReadOnly();
|
|
|
|
GroupBy = groupBy?.ToReadOnly();
|
|
|
|
GroupBy = groupBy?.ToReadOnly();
|
|
|
|
Take = take;
|
|
|
|
Take = take;
|
|
|
|
Skip = skip;
|
|
|
|
Skip = skip;
|
|
|
|
IsReverse = isReverse;
|
|
|
|
IsReverse = isReverse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SelectExpression(Alias alias, IEnumerable<ColumnDeclaration> columns, Expression from, Expression? where, IEnumerable<OrderExpression>? orderBy, IEnumerable<Expression>? groupBy)
|
|
|
|
public SelectExpression(Alias alias, IEnumerable<ColumnDeclaration> columns, Expression from, Expression? where, IEnumerable<OrderExpression>? orderBy, IEnumerable<Expression>? groupBy)
|
|
|
|
: this(alias, columns, from, where, orderBy, groupBy, false, null, null, false)
|
|
|
|
: this(alias, columns, from, where, orderBy, groupBy, false, null, null, false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SelectExpression(Alias alias, IEnumerable<ColumnDeclaration> columns, Expression from, Expression? where)
|
|
|
|
public SelectExpression(Alias alias, IEnumerable<ColumnDeclaration> columns, Expression from, Expression? where)
|
|
|
|
: this(alias, columns, from, where, null, null)
|
|
|
|
: this(alias, columns, from, where, null, null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyCollection<ColumnDeclaration> Columns { get; }
|
|
|
|
public ReadOnlyCollection<ColumnDeclaration> Columns { get; }
|
|
|
|
public Expression From { get; }
|
|
|
|
public Expression From { get; }
|
|
|
|
public Expression? Where { get; }
|
|
|
|
public Expression? Where { get; }
|
|
|
|
public ReadOnlyCollection<OrderExpression>? OrderBy { get; }
|
|
|
|
public ReadOnlyCollection<OrderExpression>? OrderBy { get; }
|
|
|
|
public ReadOnlyCollection<Expression>? GroupBy { get; }
|
|
|
|
public ReadOnlyCollection<Expression>? GroupBy { get; }
|
|
|
|
public bool IsDistinct { get; }
|
|
|
|
public bool IsDistinct { get; }
|
|
|
|
public Expression? Skip { get; }
|
|
|
|
public Expression? Skip { get; }
|
|
|
|
public Expression? Take { get; }
|
|
|
|
public Expression? Take { get; }
|
|
|
|
public bool IsReverse { get; }
|
|
|
|
public bool IsReverse { get; }
|
|
|
|
public string QueryText => SqlFormatter.Format(this);
|
|
|
|
public string QueryText => SqlFormatter.Format(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return HashCode.Combine(HashCode.Combine(Alias, Columns, From, Where, OrderBy), GroupBy, IsDistinct, Skip, Take, IsReverse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (obj is not SelectExpression second)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Alias.Equals(second.Alias)
|
|
|
|
|
|
|
|
&& Columns.Equals(second.Columns)
|
|
|
|
|
|
|
|
&& From.Equals(second.From)
|
|
|
|
|
|
|
|
&& Where == second.Where
|
|
|
|
|
|
|
|
&& OrderBy == second.OrderBy
|
|
|
|
|
|
|
|
&& GroupBy == second.GroupBy
|
|
|
|
|
|
|
|
&& IsDistinct == second.IsDistinct
|
|
|
|
|
|
|
|
&& Skip == second.Skip
|
|
|
|
|
|
|
|
&& Take == second.Take
|
|
|
|
|
|
|
|
&& IsReverse == second.IsReverse;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|