You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Connected.Expressions.Formatters;
|
|
|
|
|
using Connected.Expressions.Serialization;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Expressions;
|
|
|
|
|
|
|
|
|
|
public sealed class ProjectionExpression : DatabaseExpression
|
|
|
|
|
{
|
|
|
|
|
public ProjectionExpression(SelectExpression source, Expression projector)
|
|
|
|
|
: this(source, projector, null)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProjectionExpression(SelectExpression source, Expression projector, LambdaExpression? aggregator)
|
|
|
|
|
: base(DatabaseExpressionType.Projection, aggregator is not null ? aggregator.Body.Type : typeof(IEnumerable<>).MakeGenericType(projector.Type))
|
|
|
|
|
{
|
|
|
|
|
Select = source;
|
|
|
|
|
Projector = projector;
|
|
|
|
|
Aggregator = aggregator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SelectExpression Select { get; }
|
|
|
|
|
public Expression Projector { get; }
|
|
|
|
|
public LambdaExpression? Aggregator { get; }
|
|
|
|
|
public bool IsSingleton => Aggregator?.Body.Type == Projector.Type;
|
|
|
|
|
public string QueryText => SqlFormatter.Format(Select);
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return DatabaseSerializer.Serialize(this);
|
|
|
|
|
}
|
|
|
|
|
}
|