示例#1
0
        private void VerifySource(Column sourceColumn, string paramName)
        {
            sourceColumn.VerifyNotNull(paramName);

            var sourceModels = sourceColumn.ScalarSourceModels;

            foreach (var sourceModel in sourceModels)
            {
                if (sourceModel != _sourceModel && sourceModel != _targetModel)
                {
                    throw new ArgumentException(DiagnosticMessages.ColumnMapper_InvalidSourceParentModelSet(sourceModel), paramName);
                }
            }
        }
示例#2
0
        private void VerifyScalarSourceModels(IModels containsBy, Column sourceColumn, string exceptionParamName)
        {
            if (sourceColumn.ScalarSourceModels.Count == 0 && sourceColumn.GetExpression() == null)
            {
                throw new ArgumentException(DiagnosticMessages.Column_EmptyScalarSourceModels, exceptionParamName);
            }

            foreach (var model in sourceColumn.ScalarSourceModels)
            {
                if (!containsBy.Contains(model))
                {
                    throw new ArgumentException(DiagnosticMessages.DbQueryBuilder_InvalidScalarSourceModel(model), exceptionParamName);
                }
            }
        }
示例#3
0
        private static DataRow Deserialize(DataRow parentDataRow, string input, int inputIndex)
        {
            var dataRowPathEndIndex    = inputIndex;
            var childModelName         = ExpectString(input, ref inputIndex, '/', '[');
            var leftSquareBracketIndex = inputIndex - 1;
            var dataRowOrdinal         = ExpectInt(input, ref inputIndex, ']');

            if (!(parentDataRow.Model[childModelName] is Model childModel))
            {
                throw new FormatException(DiagnosticMessages.DataRow_FromString_InvalidChildModelName(childModelName, input.Substring(0, dataRowPathEndIndex)));
            }

            var result = GetDataRow(parentDataRow[childModel], dataRowOrdinal, input, leftSquareBracketIndex);

            return(inputIndex == input.Length ? result : Deserialize(result, input, inputIndex));
        }
示例#4
0
        internal void Add(Column item)
        {
            Debug.Assert(Model.DesignMode);

            var columns = Columns;

            if (columns.Contains(item.FullName))
            {
                throw new InvalidOperationException(DiagnosticMessages.ColumnCollection_DuplicateModelId(item.DeclaringType, item.FullName));
            }

            columns.Add(item);
            if (item.IsSystem)
            {
                SystemColumnCount++;
            }
        }
示例#5
0
        private static string ExpectString(string input, ref int inputIndex, char endChar)
        {
            var startIndex = inputIndex;

            while (inputIndex < input.Length && input[inputIndex] != endChar)
            {
                inputIndex++;
            }

            if (inputIndex == input.Length)
            {
                throw new FormatException(DiagnosticMessages.DataRow_FromString_ExpectChar(endChar, input.Substring(0, startIndex)));
            }

            var result = input.Substring(startIndex, inputIndex - startIndex);

            inputIndex++;
            return(result);
        }
示例#6
0
        /// <summary>Build the <see cref="ColumnMapping"/> between source column and target column ordinal.</summary>
        /// <param name="targetColumnOrdinal">The target column ordinal.</param>
        /// <param name="sourceColumn">The source column.</param>
        /// <returns>This <see cref="ColumnMapper"/>.</returns>
        public ColumnMapper Select(Column sourceColumn, int targetColumnOrdinal)
        {
            var targetColumns = _targetModel.Columns;

            if (targetColumnOrdinal < 0 || targetColumnOrdinal >= targetColumns.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(targetColumnOrdinal));
            }

            var targetColumn = targetColumns[targetColumnOrdinal];

            VerifySource(sourceColumn, nameof(sourceColumn));
            if (sourceColumn.DataType != targetColumn.DataType)
            {
                throw new ArgumentException(DiagnosticMessages.ColumnMapper_InvalidSourceDataType(sourceColumn.DataType, targetColumn.DataType), nameof(sourceColumn));
            }

            _result.Add(new ColumnMapping(sourceColumn, targetColumn));
            return(this);
        }
示例#7
0
        private void MergeComputation(Column baseColumn, Column computationColumn, bool isDirect)
        {
            if (baseColumn == computationColumn)
            {
                throw new InvalidOperationException(DiagnosticMessages.ComputationManager_CircularComputation(baseColumn.Name));
            }

            if (baseColumn.ParentModel != null)
            {
                _computationManager.AddDependency(baseColumn, computationColumn, isDirect);
                isDirect = false;
            }

            if (baseColumn.IsExpression)
            {
                var baseBaseColumns = baseColumn.GetExpression().BaseColumns;
                foreach (var baseBaseColumn in baseBaseColumns)
                {
                    MergeComputation(baseBaseColumn, computationColumn, isDirect);
                }
            }
        }