Esempio n. 1
0
        private DbQuery <TTarget> BuildJsonQuery <TSource, TTarget>(DataSet <TSource> dataSet, TTarget targetModel, Action <ColumnMapper, TSource, TTarget> columnMappingsBuilder)
            where TSource : class, IEntity, new()
            where TTarget : class, IEntity, new()
        {
            var result = CreateQuery <TTarget>(targetModel, (builder, _) =>
            {
                var columnMappings = ColumnMapping.Map(dataSet._, _, columnMappingsBuilder, true);

                var json = dataSet.ForJson(null, isPretty: false);

                var source               = JsonTable <TSource>(json, SYS_DATASET_ORDINAL);
                var sourceColumns        = source.Model.GetColumns();
                var dataSetOrdinalColumn = sourceColumns[SYS_DATASET_ORDINAL];
                builder.From(source, out var _);
                for (int i = 0; i < columnMappings.Count; i++)
                {
                    var sourceColumn = sourceColumns[columnMappings[i].Source.Ordinal];
                    var targetColumn = columnMappings[i].Target;
                    builder.UnsafeSelect(sourceColumn, targetColumn);
                }
                builder.OrderBy(dataSetOrdinalColumn.Asc());
            });

            result.UpdateOriginalDataSource(dataSet, true);
            return(result);
        }