Ejemplo n.º 1
0
        protected internal IEnumerable <object> GetRelationObjects(QuerySpec filter, TableSchema.Relation parentRelation, object parentObject)
        {
            var objects = from o in DataProvider.GetObjects(filter.Native, Schema)
                          select Ir.WithLoadedRelations(Schema.UpdateObject(Activator.CreateInstance(Schema.ObjectType), o), Schema.DatasetRelations);

            if (parentRelation?.ReverseRelation != null)
            {
                objects = from o in objects select parentRelation.ReverseRelation.SetField(o, parentObject);
            }

            if (filter.Code != null)
            {
                objects = from o in objects where filter.Code.IsFilterMatch(o) select o;
            }

            return(objects);
        }
Ejemplo n.º 2
0
        internal TScalar GetAggregate <TScalar>(Aggregate aggregate, QuerySpec querySpec)
        {
            if (querySpec.Native != null && querySpec.Code == null)
            {
                var result = DataProvider.GetScalar(aggregate, querySpec.Native, Schema).Convert <TScalar>();

                // This awkward hack is needed because the .NET Sum() method will return 0 (zero) on a collection
                // of nullable numbers. Since Iridium tries to honor the .NET LINQ contract, any null value
                // returned from the database needs to be converted to zero.
                if (aggregate == Aggregate.Sum && typeof(TScalar).Inspector().IsNullable&& result == null)
                {
                    result = (TScalar)typeof(TScalar).Inspector().RealType.Inspector().DefaultValue();
                }

                return(result);
            }

            if (querySpec.Code == null)
            {
                return(default);
Ejemplo n.º 3
0
        internal QuerySpec CreateQuerySpec(FilterSpec filter, ScalarSpec scalarSpec = null, int?skip = null, int?take = null, SortOrderSpec sortSpec = null)
        {
            if (DataProvider.SupportsQueryTranslation())
            {
                return(DataProvider.CreateQuerySpec(filter, scalarSpec, sortSpec, skip, take, Schema));
            }

            var querySpec = new QuerySpec(new CodeQuerySpec(), null);

            var codeQuerySpec = (CodeQuerySpec)querySpec.Code;

            if (filter != null)
            {
                foreach (var expression in filter.Expressions)
                {
                    codeQuerySpec.AddFilter(Schema, expression);
                }
            }

            if (sortSpec != null)
            {
                foreach (var expression in sortSpec.Expressions)
                {
                    codeQuerySpec.AddSort(Schema, expression.Expression, expression.SortOrder);
                }
            }

            if (scalarSpec != null)
            {
                codeQuerySpec.AddScalar(Schema, scalarSpec.Expression);
            }

            codeQuerySpec.Skip = skip;
            codeQuerySpec.Take = take;

            return(querySpec);
        }