예제 #1
0
 public ColumnWithAliasSourceQueryExpression(string columnName, IAliasIdentifier sourceIdentifier,
                                             SqlStorageField sqlStorageField) : base(columnName, sourceIdentifier == null ? null : new AliasReferenceQueryExpression(sourceIdentifier))
 {
     ColumnName       = columnName;
     SourceIdentifier = sourceIdentifier;
     SqlStorageField  = sqlStorageField;
 }
예제 #2
0
 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
                                                             ));
 }
예제 #3
0
        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)
                    ));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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
                        ));
        }
예제 #6
0
        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
                                  ));
        }
예제 #7
0
        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));
        }
예제 #8
0
 public SqlUpdateBuilder <TEntity> AndWhere <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value)
 {
     _whereBuilder.AndAlso(field, comparisonType, value);
     return(this);
 }
예제 #9
0
 IWhereQueryBuilder <TEntity> IWhereQueryBuilder <TEntity> .OrWhere <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value)
 => OrWhere(field, comparisonType, value);
예제 #10
0
 public SqlDeleteBuilder <TEntity> OrWhere <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value)
 {
     _whereBuilder.OrElse(field, comparisonType, value);
     return(this);
 }
예제 #11
0
 public Mapping.IResultMapper <T> Select <T>(SqlStorageField <TEntity, T> storageField)
 => _projectionBuilder.Select(storageField);
예제 #12
0
 public SqlSelectBuilder <TEntity> OrHaving <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value)
 {
     _havingBuilder.OrElse(field, comparisonType, value);
     return(this);
 }
예제 #13
0
 public void EnterMember(SqlStorageField <TEntity> field)
 {
     //  noop
 }
예제 #14
0
 public SqlSelectBuilder <TEntity> OrderByDescending <TValue>(SqlStorageField <TEntity, TValue> field)
 {
     _orderByBuilder.OrderByDescending(field);
     return(this);
 }
예제 #15
0
 IOrderByQueryBuilder <TEntity> IOrderByQueryBuilder <TEntity> .OrderByDescending <TValue>(SqlStorageField <TEntity, TValue> field)
 => OrderByDescending(field);
예제 #16
0
 IOrderByQueryBuilder <TEntity> IOrderByQueryBuilder <TEntity> .OrderBy <TValue>(SqlStorageField <TEntity, TValue> field)
 => OrderBy(field);
예제 #17
0
 public SqlSelectBuilder <TEntity> GroupBy <TValue>(SqlStorageField <TEntity, TValue> field)
 {
     _groupByBuilder.GroupBy(field);
     return(this);
 }
예제 #18
0
 IGroupByQueryBuilder <TEntity> IGroupByQueryBuilder <TEntity> .GroupBy <TValue>(SqlStorageField <TEntity, TValue> field)
 => GroupBy(field);
예제 #19
0
 public bool CanEnterMember(SqlStorageField <TEntity> field)
 {
     return(true);
 }
예제 #20
0
 IRangeQueryBuilder <TEntity> IRangeQueryBuilder <TEntity> .Offset <TValue>(SqlStorageField <TEntity, TValue> field)
 => Offset(field);
예제 #21
0
 public SqlSelectBuilder <TEntity> Offset <TValue>(SqlStorageField <TEntity, TValue> field)
 {
     _rangeBuilder.Offset(field);
     return(this);
 }
예제 #22
0
 IRangeQueryBuilder <TEntity> IRangeQueryBuilder <TEntity> .Limit <TValue>(SqlStorageField <TEntity, TValue> field)
 => Limit(field);
예제 #23
0
 IHavingQueryBuilder <TEntity> IHavingQueryBuilder <TEntity> .OrHaving <TValue>(SqlStorageField <TEntity, TValue> field, SqlComparisonOperator comparisonType, TValue value)
 => OrHaving(field, comparisonType, value);