private Column ResolveColumnReference(Table table, Column column) { ColumnReference columnRef = column as ColumnReference; if (columnRef == null) { return column; } var result = table.Columns.SingleOrDefault(c => c.Name == columnRef.Name); if (result == null) { throw new TaupoInvalidOperationException("The column '" + columnRef.Name + "' was not found in '" + table + "'"); } return result; }
/// <summary> /// Adds new <see cref="Column"/> to the table. /// </summary> /// <param name="column">Column to add.</param> public void Add(Column column) { this.Columns.Add(column); }
/// <summary> /// Gets the ordinal of the specified column. /// </summary> /// <param name="column">The column.</param> /// <returns>Zero-based ordinal of the specified column.</returns> /// <remarks>This function throws if the column was not found.</remarks> public int GetColumnOrdinal(Column column) { int ordinal; if (!this.TableType.TryGetColumnOrdinal(column, out ordinal)) { throw new TaupoInvalidOperationException("Column '" + column.Name + "' not found in " + this); } return ordinal; }
private DataType ConvertToDatabaseType(DataType dataType) { DataType databaseType = null; var primitiveReturnType = dataType as PrimitiveDataType; if (primitiveReturnType != null) { databaseType = primitiveReturnType.Clone(); } else { var collectionReturnType = dataType as CollectionDataType; ExceptionUtilities.CheckObjectNotNull(collectionReturnType, "Unsupported data type: '{0}'. Only primitive data types and collection of rows can be converted to a database type.", dataType); var rowDataType = collectionReturnType.ElementDataType as RowDataType; ExceptionUtilities.CheckObjectNotNull(rowDataType, "Unsupported collection's element data type: '{0}'. Only row data type is supported as element data type of a collection when converting to a database type.", collectionReturnType.ElementDataType); TableDataType table = new TableDataType(); foreach (var property in rowDataType.Definition.Properties) { var primitivePropertyType = property.PropertyType as PrimitiveDataType; ExceptionUtilities.CheckObjectNotNull(primitivePropertyType, "Unsupported property's data type: '{0}'. Only primitive data types are supported.", property.PropertyType); var column = new Column(property.Name, primitivePropertyType); this.ApplyDataGeneratorAnnotationToStoreItem(column, property); table.Columns.Add(column); } databaseType = table; } return databaseType; }
private Column ConvertPropertyToColumn(MemberProperty prop) { Column column = new Column(prop.Name, prop.PropertyType); if (prop.Annotations.OfType<StoreGeneratedPatternAnnotation>().Where(a => a == StoreGeneratedPatternAnnotation.Identity).Any()) { column.Annotations.Add(new IdentityColumnAnnotation()); } if (prop.Annotations.OfType<StoreGeneratedPatternAnnotation>().Where(a => a == StoreGeneratedPatternAnnotation.Computed).Any()) { column.Annotations.Add(new ComputedColumnAnnotation()); } return column; }