ResolveTableInfo() public method

public ResolveTableInfo ( UnresolvedTableInfo tableInfo, UniqueIdentifierGenerator generator ) : IResolvedTableInfo
tableInfo Remotion.Linq.SqlBackend.SqlStatementModel.Unresolved.UnresolvedTableInfo
generator UniqueIdentifierGenerator
return IResolvedTableInfo
Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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();
    }