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); } } }
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); } } }
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)); }
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++; } }
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); }
/// <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); }
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); } } }