protected virtual void CreateTypeColumnForClass(IClassMap classMap, IDomainMap targetDomainMap, bool generateMappings) { ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IColumnMap columnMap = null; string tableName = ""; string name = ""; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (classMap.Table.Length > 0) { tableName = classMap.Table; } else { tableName = GetTableNameForClass(classMap); } tableMap = addToSourceMap.GetTableMap(tableName); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = tableName; tableMap.SourceMap = addToSourceMap; } if (classMap.TypeColumn.Length > 0) { name = classMap.TypeColumn; } else { name = GetTypeColumnNameForClass(classMap); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = DbType.AnsiStringFixedLength; columnMap.Length = 1; columnMap.Precision = 1; columnMap.Scale = 0; columnMap.IsPrimaryKey = true; columnMap.AllowNulls = false; if (generateMappings & classMap.TypeColumn.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.DomainMap = targetDomainMap; } classMapClone.TypeColumn = name; } }
protected virtual void CreateTableForClass(IClassMap classMap, IDomainMap targetDomainMap, bool generateMappings) { ITableMap tableMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; string name = ""; ISourceMap sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (classMap.Table.Length > 0) { name = classMap.Table; } else { name = GetTableNameForClass(classMap); } tableMap = addToSourceMap.GetTableMap(name); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = name; tableMap.SourceMap = addToSourceMap; } if (generateMappings & classMap.Table.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.DomainMap = targetDomainMap; } classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } classMapClone.DomainMap = targetDomainMap; } }