Example #1
0
        private void BeforeDeserializing(StreamingContext context)
        {
            Schema = CSSchema.Get(typeof(TObjectType));

            if (!string.IsNullOrEmpty(Schema.DefaultSortExpression))
            {
                OrderBy = Schema.DefaultSortExpression;
            }
        }
Example #2
0
        private void Initialize()
        {
            if (_schema == null)
            {
                _schema = CSSchema.Get(GetType());
            }

            _dataState = CSObjectDataState.New;

            _fieldData = new CSFieldValueCollection(this);
        }
Example #3
0
        private static object GetScalar(string fieldName, string tableAlias, CSAggregate aggregate, CSFilter queryFilter, string orderBy)
        {
            CSSchema schema = CSSchema.Get(typeof(T));

            if (tableAlias == null)
            {
                tableAlias = CSNameGenerator.NextTableAlias;
            }

            if (orderBy == null)
            {
                orderBy = "";
            }

            string aggregateExpr = null;

            int maxRows = 0;

            switch (aggregate)
            {
            case CSAggregate.None: aggregateExpr = "{0}"; maxRows = 1;    break;

            case CSAggregate.Sum: aggregateExpr = "sum({0})";            break;

            case CSAggregate.SumDistinct: aggregateExpr = "sum(distinct {0})";   break;

            case CSAggregate.Count: aggregateExpr = "count(*)";            break;

            case CSAggregate.CountDistinct: aggregateExpr = "count(distinct {0})"; break;

            case CSAggregate.Avg: aggregateExpr = "avg({0})";            break;

            case CSAggregate.AvgDistinct: aggregateExpr = "avg(distinct {0})";   break;

            case CSAggregate.Max: aggregateExpr = "max({0})";            break;

            case CSAggregate.Min: aggregateExpr = "min({0})";            break;
            }

            CSJoinList joins = new CSJoinList();

            if (fieldName != "*")
            {
                fieldName = CSExpressionParser.ParseFilter(fieldName, schema, tableAlias, joins);
            }

            string whereFilter = CSExpressionParser.ParseFilter(queryFilter.Expression, schema, tableAlias, joins);

            orderBy = CSExpressionParser.ParseOrderBy(orderBy, schema, tableAlias, joins);

            string sqlQuery = schema.DB.BuildSelectSQL(schema.TableName, tableAlias, new[] { String.Format(aggregateExpr, fieldName) }, null, joins.BuildJoinExpressions(), whereFilter, orderBy, 1, maxRows, false, false);

            return(schema.DB.GetScalar(sqlQuery, queryFilter.Parameters));
        }
Example #4
0
 public CSList()
     : base(CSSchema.Get(typeof(TObjectType)))
 {
 }