public ColumnWithAliasSourceQueryExpression(string columnName, IAliasIdentifier sourceIdentifier, SqlStorageField sqlStorageField) : base(columnName, sourceIdentifier == null ? null : new AliasReferenceQueryExpression(sourceIdentifier)) { ColumnName = columnName; SourceIdentifier = sourceIdentifier; SqlStorageField = sqlStorageField; }
public ModelState(SqlDataModelBuilder modelBuilder, IReadOnlyList <string> basePath, SqlStorageField <TEntity> foreignKeyField) { SqlFieldConfigurations = modelBuilder.ModelledFields; BasePath = basePath; JoinSpecification = new JoinSpecification <TEntity>(foreignKeyField.JoinSpecification, typeof(T), $"_{string.Join("_", basePath)}", new JoinColumnPair( foreignKeyField.ColumnName, SqlFieldConfigurations.First(q => q.Options.IsPrimaryKey).Options.ColumnName )); }
public void OrElse <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value) { if (field.RequiresJoin) { foreach (var(joinBuilder, _) in field.JoinSpecification.CreateJoin(_dataSchema, field, _tableIdentifier)) { AddJoin(joinBuilder); } } _expression = _expression.OrElse( CreateComparison( QueryExpression.Column(field.ColumnName), comparisonType, QueryExpression.Value(value) )); }
public IResultMapper <T> Select <T>(SqlStorageField <TEntity, T> field) { var alias = $"__AutoAlias_{_projectionExpressions.Count}"; _projectionExpressions.Add( alias, QueryExpression.As( QueryExpression.Column(field.ColumnName), alias, out var _) ); if (field.RequiresJoin) { _joinBuilders.AddRange( field.JoinSpecification.CreateJoin(_dataSchema, field, _tableIdentifier) .Select(q => q.Builder) ); } return(new ValueMapper <T>(alias)); }
public void GroupBy <TValue>(SqlStorageField <TEntity, TValue> field) { if (!field.RequiresJoin) { GroupBy(new SqlValueExpression <TEntity, TValue>( QueryExpression.Column(field.ColumnName), null )); return; } var joins = field.JoinSpecification.CreateJoin(_dataSchema, field, _tableIdentifier) .Select(q => q.Builder).ToArray(); GroupBy(new SqlValueExpression <TEntity, TValue>( QueryExpression.Column(field.ColumnName), joins )); }
public void OrderByDescending <TValue>(SqlStorageField <TEntity, TValue> field) { // todo: support multiple nested JOINs if (!field.RequiresJoin) { OrderByDescending(new SqlValueExpression <TEntity, TValue>( QueryExpression.Column(field.ColumnName), null )); return; } var joins = field.JoinSpecification.CreateJoin(_dataSchema, field, _tableIdentifier) .Select(q => q.Builder).ToArray(); OrderByDescending(new SqlValueExpression <TEntity, TValue>( QueryExpression.Column(field.ColumnName), joins )); }
public T ReadField <T>(SqlStorageField <TEntity> field) { var ord = _queryResult.GetOrdinal(field.FieldName); if (_queryResult.IsDBNull(ord)) { return(default(T)); } if (typeof(T).IsEnum) { return((T)(object)QueryTypeReaders.GetTypeReader <int>()(_queryResult, ord)); } var reader = QueryTypeReaders.GetTypeReader <T>(); if (reader == null) { throw new System.InvalidOperationException("Attempting to read an unsupported data type from query result."); } return(reader(_queryResult, ord)); }
public SqlUpdateBuilder <TEntity> AndWhere <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value) { _whereBuilder.AndAlso(field, comparisonType, value); return(this); }
IWhereQueryBuilder <TEntity> IWhereQueryBuilder <TEntity> .OrWhere <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value) => OrWhere(field, comparisonType, value);
public SqlDeleteBuilder <TEntity> OrWhere <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value) { _whereBuilder.OrElse(field, comparisonType, value); return(this); }
public Mapping.IResultMapper <T> Select <T>(SqlStorageField <TEntity, T> storageField) => _projectionBuilder.Select(storageField);
public SqlSelectBuilder <TEntity> OrHaving <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value) { _havingBuilder.OrElse(field, comparisonType, value); return(this); }
public void EnterMember(SqlStorageField <TEntity> field) { // noop }
public SqlSelectBuilder <TEntity> OrderByDescending <TValue>(SqlStorageField <TEntity, TValue> field) { _orderByBuilder.OrderByDescending(field); return(this); }
IOrderByQueryBuilder <TEntity> IOrderByQueryBuilder <TEntity> .OrderByDescending <TValue>(SqlStorageField <TEntity, TValue> field) => OrderByDescending(field);
IOrderByQueryBuilder <TEntity> IOrderByQueryBuilder <TEntity> .OrderBy <TValue>(SqlStorageField <TEntity, TValue> field) => OrderBy(field);
public SqlSelectBuilder <TEntity> GroupBy <TValue>(SqlStorageField <TEntity, TValue> field) { _groupByBuilder.GroupBy(field); return(this); }
IGroupByQueryBuilder <TEntity> IGroupByQueryBuilder <TEntity> .GroupBy <TValue>(SqlStorageField <TEntity, TValue> field) => GroupBy(field);
public bool CanEnterMember(SqlStorageField <TEntity> field) { return(true); }
IRangeQueryBuilder <TEntity> IRangeQueryBuilder <TEntity> .Offset <TValue>(SqlStorageField <TEntity, TValue> field) => Offset(field);
public SqlSelectBuilder <TEntity> Offset <TValue>(SqlStorageField <TEntity, TValue> field) { _rangeBuilder.Offset(field); return(this); }
IRangeQueryBuilder <TEntity> IRangeQueryBuilder <TEntity> .Limit <TValue>(SqlStorageField <TEntity, TValue> field) => Limit(field);
IHavingQueryBuilder <TEntity> IHavingQueryBuilder <TEntity> .OrHaving <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value) => OrHaving(field, comparisonType, value);