/// <summary> /// Creates a Custom Model assembly with given name and extended type definitions and saves it to assemblyName.dll /// </summary> /// <param name="assemblyName">The name of the assembly (will be saved as assemblyName.dll)</param> /// <param name="extendedTables">The enumeration of extended tables to be implemented</param> public static void CreateCustomModelAssembly(string assemblyName, IEnumerable <ExtendedTable> extendedTables) { string assemblyFileName = assemblyName + ".dll"; var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(assemblyName), AssemblyBuilderAccess.RunAndSave); var moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyFileName, assemblyFileName); var derivedTypes = new List <Type>(); var tableMappings = new TableMappings(); foreach (var extendedTable in extendedTables) { var tableMapping = new TableMapping(extendedTable.TableName); foreach (var extendedType in extendedTable.Types) { var derivedType = CreateDerivedType(moduleBuilder, extendedTable, extendedType); derivedTypes.Add(derivedType); tableMapping.Add(new TypeMapping(extendedType.BaseType, derivedType)); } tableMappings.Add(tableMapping); } SerializeMappings(assemblyName, tableMappings); assemblyBuilder.Save(assemblyFileName); }
internal int IndexOfDataSetTable(string dataSetTable) { if (null != _tableMappings) { return(TableMappings.IndexOfDataSetTable(dataSetTable)); } return(-1); }
private static void SerializeMappings(string assemblyName, TableMappings mapper) { using (var xmlWriter = XmlWriter.Create(assemblyName + ".xml")) { var serializer = new DataContractSerializer(mapper.GetType()); serializer.WriteObject(xmlWriter, mapper); } }
public int Update(DataTable dataTable) { /* * int index = TableMappings.IndexOfDataSetTable (dataTable.TableName); * if (index < 0) * throw new ArgumentException (); * return Update (dataTable, TableMappings [index]); */ DataTableMapping tableMapping = TableMappings.GetByDataSetTable(dataTable.TableName); if (tableMapping == null) { tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction( TableMappings, dataTable.TableName, dataTable.TableName, MissingMappingAction); if (tableMapping != null) { foreach (DataColumn col in dataTable.Columns) { if (tableMapping.ColumnMappings.IndexOf(col.ColumnName) >= 0) { continue; } DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, col.ColumnName, MissingMappingAction); if (columnMapping == null) { columnMapping = new DataColumnMapping(col.ColumnName, col.ColumnName); } tableMapping.ColumnMappings.Add(columnMapping); } } else { ArrayList cmc = new ArrayList(); foreach (DataColumn col in dataTable.Columns) { cmc.Add(new DataColumnMapping(col.ColumnName, col.ColumnName)); } tableMapping = new DataTableMapping( dataTable.TableName, dataTable.TableName, cmc.ToArray(typeof(DataColumnMapping)) as DataColumnMapping []); } } return(Update(dataTable, tableMapping)); }
internal ModelVisitor(IEnumerable <AptifyEntityMetadata> entities, TableMappings mappings) { if (entities == null) { throw new ArgumentNullException("entities"); } if (mappings == null) { throw new ArgumentNullException("mappings"); } this.entities = entities; this.mappings = mappings; }
protected DataAdapter(DataAdapter from) { AcceptChangesDuringFill = from.AcceptChangesDuringFill; ContinueUpdateOnError = from.ContinueUpdateOnError; MissingMappingAction = from.MissingMappingAction; MissingSchemaAction = from.MissingSchemaAction; if (from.tableMappings != null) { foreach (ICloneable cloneable in from.TableMappings) { TableMappings.Add(cloneable.Clone()); } } acceptChangesDuringUpdate = from.AcceptChangesDuringUpdate; fillLoadOption = from.FillLoadOption; returnProviderSpecificTypes = from.ReturnProviderSpecificTypes; }
protected DataAdapter(DataAdapter adapter) { AcceptChangesDuringFill = adapter.AcceptChangesDuringFill; ContinueUpdateOnError = adapter.ContinueUpdateOnError; MissingMappingAction = adapter.MissingMappingAction; MissingSchemaAction = adapter.MissingSchemaAction; if (adapter.tableMappings != null) { foreach (ICloneable cloneable in adapter.TableMappings) { TableMappings.Add(cloneable.Clone()); } } #if NET_2_0 acceptChangesDuringUpdate = adapter.AcceptChangesDuringUpdate; fillLoadOption = adapter.FillLoadOption; returnProviderSpecificTypes = adapter.ReturnProviderSpecificTypes; #endif }
internal TableMappings MapTables(IEnumerable <AptifyEntityMetadata> entities, ActiveRecordModelCollection models) { var mappings = new TableMappings( ); var visitors = new List <IVisitor> { new ModelVisitor(entities, mappings), new HasManyVisitor(entities, mappings), new BelongsToVisitor(mappings), new PropertyVisitor(mappings), }; foreach (IVisitor visitor in visitors) { foreach (ActiveRecordModel model in models) { visitor.VisitModel(model); } } return(mappings); }
private System.Data.DataTable PrepareDataTable(DataSet dataSet, ref string dataTableName) { if (dataTableName == null) { dataTableName = "Table"; } // MAPPING if (this.HasTableMappings() && TableMappings.Contains(dataTableName)) { ITableMapping mapping = this.TableMappings[dataTableName]; if (mapping != null) { dataTableName = mapping.DataSetTable; } } else // Or No Mapping { dataTableName = dataSet.DataSetName; } System.Data.DataTable dt = new System.Data.DataTable(dataTableName); dataSet.Tables.Add(dt); // For The filling columns, add their columns name foreach (KeyValuePair <string, Type> columnName in this.columnsFilling.Values) { dt.Columns.Add(columnName.Key, columnName.Value /*Type of Column*/); } foreach (string columnName in this.columnsFillingConstant.Keys) { dt.Columns.Add(columnName); } return(dt); }
public int Update(DataRow [] dataRows) { if (dataRows == null) { throw new ArgumentNullException("dataRows"); } if (dataRows.Length == 0) { return(0); } if (dataRows [0] == null) { throw new ArgumentException("dataRows[0]."); } DataTable table = dataRows [0].Table; if (table == null) { throw new ArgumentException("table is null reference."); } // all rows must be in the same table for (int i = 0; i < dataRows.Length; i++) { if (dataRows [i] == null) { throw new ArgumentException("dataRows[" + i + "]."); } if (dataRows [i].Table != table) { throw new ArgumentException( " DataRow[" + i + "] is from a different DataTable than DataRow[0]."); } } // get table mapping for this rows DataTableMapping tableMapping = TableMappings.GetByDataSetTable(table.TableName); if (tableMapping == null) { tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction( TableMappings, table.TableName, table.TableName, MissingMappingAction); if (tableMapping != null) { foreach (DataColumn col in table.Columns) { if (tableMapping.ColumnMappings.IndexOf(col.ColumnName) >= 0) { continue; } DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, col.ColumnName, MissingMappingAction); if (columnMapping == null) { columnMapping = new DataColumnMapping(col.ColumnName, col.ColumnName); } tableMapping.ColumnMappings.Add(columnMapping); } } else { ArrayList cmc = new ArrayList(); foreach (DataColumn col in table.Columns) { cmc.Add(new DataColumnMapping(col.ColumnName, col.ColumnName)); } tableMapping = new DataTableMapping( table.TableName, table.TableName, cmc.ToArray(typeof(DataColumnMapping)) as DataColumnMapping []); } } DataRow[] copy = table.NewRowArray(dataRows.Length); Array.Copy(dataRows, 0, copy, 0, dataRows.Length); return(Update(copy, tableMapping)); }
internal HasManyVisitor(IEnumerable <AptifyEntityMetadata> entities, TableMappings mappings) { this.mappings = mappings; this.entities = entities; }
public PropertyVisitor(TableMappings mappings) { this.mappings = mappings; }
public BelongsToVisitor(TableMappings mappings) { this.mappings = mappings; }