private void AppendSelectFrom(List <Expression <Func <TEntity, object> > > propertySelections) { propertySelections?.ForEach(PropertySelectionResolver.ValidatePropertyExpression); var table = MetadataResolver.TableName <TEntity>(); var selections = PropertySelectionResolver.GetSelectionsFromProperties(propertySelections); string selectFrom = $"SELECT {selections} FROM {table}"; _sqlBuilder.Append(selectFrom); }
public SelectFromBuilder <TEntity> Property(Expression <Func <TEntity, TResult> > selection) { if (selection == null) { throw new ArgumentNullException(nameof(selection), "Property selection expression must be provided."); } // validate expression PropertySelectionResolver.ValidatePropertyExpression(selection); _selection = selection; return(this); }
public (Type propertyType, PostgresDataType dataType) GetMetadata() { if (_selection == null) { throw new InvalidOperationException("Selection must be configured to get metadata."); } if (!PropertySelectionResolver.TryGetColumnFromExpression(_selection, out TableColumn column)) { throw new InvalidOperationException("Failed to resolve metadata from selection expression."); } return(column.PropertyType, column.DataType); }
public string BuildQuery() { var table = MetadataResolver.TableName <TEntity>(); var selection = PropertySelectionResolver.GetSelectionFromProperty(_selection); string selectFrom = $"SELECT {selection} FROM {table}"; _sqlBuilder.Append(selectFrom); if (_where != null) { var whereCondition = WhereConditionBuilder <TEntity> .FromExpression(_where); _sqlBuilder.Append($"WHERE {whereCondition}"); } return(_sqlBuilder.GetResult(omitTerminatingSemiColon: true)); }