예제 #1
0
        public override IOperation Extract(Process process, Entity entity, bool firstRun)
        {
            if (Schemas && entity.Schema.Equals(string.Empty))
            {
                entity.Schema = DefaultSchema;
            }
            var p = new PartialProcessOperation(process);

            if (entity.HasSqlOverride())
            {
                p.Register(new SqlOverrideOperation(entity, this));
            }
            else
            {
                if (entity.PrimaryKey.WithInput().Any())
                {
                    p.Register(new EntityKeysSaveOperation(entity));
                    p.Register(new EntityKeysToOperations(ref entity, this, firstRun));
                    p.Register(new SerialUnionAllOperation(entity));
                }
                else
                {
                    entity.SqlOverride = SqlTemplates.Select(entity, this);
                    p.Register(new SqlOverrideOperation(entity, this));
                }
            }
            return(p);
        }
        public string SelectByKeys(IEnumerable<Row> rows) {
            var tableName = _connection.TableVariable ? "@KEYS" : "keys_" + _entity.Name;
            var noCount = _connection.NoCount ? "SET NOCOUNT ON;\r\n" : string.Empty;
            var sql = noCount +
                _connection.TableQueryWriter.WriteTemporary(_connection, tableName, _key, false) +
                SqlTemplates.BatchInsertValues(50, tableName, _key, rows, _connection) + Environment.NewLine +
                SqlTemplates.Select(_entity.Fields, _entity.Name, tableName, _connection, _entity.Schema, string.Empty) +
                (_connection.TableVariable ? string.Empty : string.Format("DROP TABLE {0};", tableName));

            Debug(sql);

            return sql;
        }
예제 #3
0
        public void TestSelectByKeysSql()
        {
            var entity = _process.Entities.First();

            var actual = SqlTemplates.Select(entity.Fields, entity.OutputName(), "@KEYS", _process.OutputConnection, "dbo", _process.OutputConnection.DefaultSchema);

            const string expected = @"
SELECT
    l.[OrderDetailKey],
    l.[OrderKey],
    l.[ProductKey],
    l.[Qty] AS [Quantity],
    l.[Price],
    l.[Properties],
    l.[RowVersion] AS [OrderDetailRowVersion]
FROM [dbo].[TestOrderDetail] l
INNER JOIN @KEYS r ON (l.[OrderDetailKey] = r.[OrderDetailKey])
OPTION (MAXDOP 2);";

            Assert.AreEqual(expected, actual);
        }