public ResolveSimpleTableInfo ( IResolvedTableInfo tableInfo, UniqueIdentifierGenerator generator ) : |
||
tableInfo | IResolvedTableInfo | |
generator | UniqueIdentifierGenerator | |
리턴 |
private static void AppendInsertScript(StringBuilder sb, object entity) { var mappingResolver = new MappingResolverStub(); var generator = new UniqueIdentifierGenerator(); var resolvedTableInfo = (ResolvedSimpleTableInfo)mappingResolver.ResolveTableInfo(new UnresolvedTableInfo(entity.GetType()), generator); var sqlEntityDefinition = mappingResolver.ResolveSimpleTableInfo(resolvedTableInfo, generator); var columnData = (from c in sqlEntityDefinition.Columns let columnName = c.ColumnName let columnValue = GetColumnValue(entity, mappingResolver, sqlEntityDefinition, columnName) select new { columnName, columnValue }).ToArray(); var columnNames = string.Join(",", columnData.Select(d => d.columnName)); var columnValues = string.Join(",", columnData.Select(d => GetSqlValueString(d.columnValue))); sb.AppendFormat("INSERT INTO [{0}] ({1}) VALUES ({2});", resolvedTableInfo.TableName, columnNames, columnValues); sb.AppendLine(); }
private static void AppendCreateTableScript (StringBuilder sb, Type type) { var mappingResolver = new MappingResolverStub(); var generator = new UniqueIdentifierGenerator(); var tableInfo = (ResolvedSimpleTableInfo) mappingResolver.ResolveTableInfo (new UnresolvedTableInfo (type), generator); var entity = mappingResolver.ResolveSimpleTableInfo (tableInfo, generator); var columnDeclarations = from c in entity.Columns let sqlTypeName = GetColumnType(c) select string.Format ("[{0}] {1}", c.ColumnName, sqlTypeName); var primaryKeyColumns = entity.Columns.Where (c => c.IsPrimaryKey).Select (c => c.ColumnName).ToArray(); string primaryKeyConstraint = ""; if (primaryKeyColumns.Length > 0) { primaryKeyConstraint = string.Format ( " CONSTRAINT PK_{0} PRIMARY KEY ({1})", tableInfo.TableName.Replace (".", "_"), string.Join (",", primaryKeyColumns)); } sb.AppendFormat ( "CREATE TABLE [{0}]{1}({1}{2}{1} {3})", tableInfo.TableName, Environment.NewLine, string.Join ("," + Environment.NewLine, columnDeclarations.Select (c => " " + c)), primaryKeyConstraint); sb.AppendLine(); }
private static void AppendInsertScript (StringBuilder sb, object entity) { var mappingResolver = new MappingResolverStub (); var generator = new UniqueIdentifierGenerator(); var resolvedTableInfo = (ResolvedSimpleTableInfo) mappingResolver.ResolveTableInfo (new UnresolvedTableInfo (entity.GetType()), generator); var sqlEntityDefinition = mappingResolver.ResolveSimpleTableInfo (resolvedTableInfo, generator); var columnData = (from c in sqlEntityDefinition.Columns let columnName = c.ColumnName let columnValue = GetColumnValue (entity, mappingResolver, sqlEntityDefinition, columnName) select new { columnName, columnValue }).ToArray(); var columnNames = string.Join (",", columnData.Select (d => d.columnName)); var columnValues = string.Join (",", columnData.Select (d => GetSqlValueString (d.columnValue))); sb.AppendFormat ("INSERT INTO [{0}] ({1}) VALUES ({2});", resolvedTableInfo.TableName, columnNames, columnValues); sb.AppendLine(); }