Пример #1
0
        public void Delete_tpt_entity_with_concurrency_and_store_generated_values()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                  .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                      modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                  .Convert(commandTrees)
                  .OfType <DbDeleteCommandTree>()
                  .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(new SqlGenerator());

            Assert.Equal(
                @"DELETE [dbo].[xspecial_orders]
WHERE (((([xid] = @xid) AND ([so_key] = @key_for_delete)) AND ([Code] = @Code)) AND ([Signature] = @Signature))

DELETE [dbo].[special_orders]
WHERE ((((([order_id] = @xid) AND ([so_key] = @key_for_delete)) AND ([Code] = @Code)) AND ([Signature] = @Signature)) AND (([OtherCustomer_CustomerId] = @OtherCustomer_CustomerId) OR ([OtherCustomer_CustomerId] IS NULL AND @OtherCustomer_CustomerId IS NULL)))
AND @@ROWCOUNT > 0

DELETE [dbo].[Orders]
WHERE ((((((([order_id] = @xid) AND ([Key] = @key_for_delete)) AND ([Code] = @Code)) AND ([Signature] = @Signature)) AND (([Name] = @Name_Original) OR ([Name] IS NULL AND @Name_Original IS NULL))) AND (([RowVersion] = @RowVersion_Original) OR ([RowVersion] IS NULL AND @RowVersion_Original IS NULL))) AND (([Customer_CustomerId] = @Customer_CustomerId) OR ([Customer_CustomerId] IS NULL AND @Customer_CustomerId IS NULL)))
AND @@ROWCOUNT > 0

SET @rows_affected = @@ROWCOUNT",
                functionSqlGenerator.GenerateDelete(convertedTrees, "rows_affected"));
        }
        public void Delete_tpt_entity_with_concurrency_and_store_generated_values()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                  .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                      modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                  .Convert(commandTrees)
                  .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"delete [dbo].[xspecial_orders]
where (((([xid] = @xid) and ([so_key] = @key_for_delete)) and ([Code] = @Code)) and ([Signature] = @Signature))

delete [dbo].[special_orders]
where ((((([order_id] = @xid) and ([so_key] = @key_for_delete)) and ([Code] = @Code)) and ([Signature] = @Signature)) and (([OtherCustomer_CustomerId] = @OtherCustomer_CustomerId) or ([OtherCustomer_CustomerId] is null and @OtherCustomer_CustomerId is null)))
and @@ROWCOUNT > 0

delete [dbo].[Orders]
where ((((((([order_id] = @xid) and ([Key] = @key_for_delete)) and ([Code] = @Code)) and ([Signature] = @Signature)) and (([Name] = @Name_Original) or ([Name] is null and @Name_Original is null))) and (([RowVersion] = @RowVersion_Original) or ([RowVersion] is null and @RowVersion_Original is null))) and (([Customer_CustomerId] = @Customer_CustomerId) or ([Customer_CustomerId] is null and @Customer_CustomerId is null)))
and @@ROWCOUNT > 0

set @rows_affected = @@ROWCOUNT",
                functionSqlGenerator.GenerateDelete(convertedTrees, "rows_affected"));
        }
        public void Delete_simple_entity()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Customer");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                  .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                      modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                  .Convert(commandTrees)
                  .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"delete [dbo].[Customers]
where ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateDelete(convertedTrees, null));
        }
Пример #4
0
        public void Delete_simple_entity()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Customer");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                  .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                      modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                  .Convert(commandTrees)
                  .OfType <DbDeleteCommandTree>()
                  .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(new SqlGenerator());

            Assert.Equal(
                @"DELETE [dbo].[Customers]
WHERE ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateDelete(convertedTrees, null));
        }
        public void Delete_value_type_concurrency_token()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Person");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                  .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                      modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                  .Convert(commandTrees)
                  .OfType <DbDeleteCommandTree>()
                  .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(new SqlGenerator());

            Assert.Equal(
                @"DELETE [dbo].[People]
WHERE (([Id] = @Id) AND ([BirthDate] = @BirthDate_Original))",
                functionSqlGenerator.GenerateDelete(convertedTrees, null));
        }
        private string GenerateFunctionSql(ICollection<DbModificationCommandTree> commandTrees, string rowsAffectedParameter)
        {
            DebugCheck.NotNull(commandTrees);
            Debug.Assert(commandTrees.Any());

            var functionSqlGenerator = new DmlFunctionSqlGenerator(_sqlGenerator);

            switch (commandTrees.First().CommandTreeKind)
            {
                case DbCommandTreeKind.Insert:
                    return functionSqlGenerator.GenerateInsert(commandTrees.Cast<DbInsertCommandTree>().ToList());
                case DbCommandTreeKind.Update:
                    return functionSqlGenerator.GenerateUpdate(commandTrees.Cast<DbUpdateCommandTree>().ToList(), rowsAffectedParameter);
                case DbCommandTreeKind.Delete:
                    return functionSqlGenerator.GenerateDelete(commandTrees.Cast<DbDeleteCommandTree>().ToList(), rowsAffectedParameter);
            }

            return null;
        }
        public void Delete_value_type_concurrency_token()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Person");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                    .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                    modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                    .Convert(commandTrees)
                    .OfType<DbDeleteCommandTree>()
                    .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(new SqlGenerator());

            Assert.Equal(
                @"DELETE [dbo].[People]
WHERE (([Id] = @Id) AND ([BirthDate] = @BirthDate_Original))",
                functionSqlGenerator.GenerateDelete(convertedTrees, null));
        }
        public void Delete_tpt_entity_with_concurrency_and_store_generated_values()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                    .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                    modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                    .Convert(commandTrees)
                    .OfType<DbDeleteCommandTree>()
                    .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(new SqlGenerator());

            Assert.Equal(
                @"DELETE [dbo].[xspecial_orders]
WHERE (((([xid] = @xid) AND ([so_key] = @key_for_delete)) AND ([Code] = @Code)) AND ([Signature] = @Signature))

DELETE [dbo].[special_orders]
WHERE ((((([order_id] = @xid) AND ([so_key] = @key_for_delete)) AND ([Code] = @Code)) AND ([Signature] = @Signature)) AND (([OtherCustomer_CustomerId] = @OtherCustomer_CustomerId) OR ([OtherCustomer_CustomerId] IS NULL AND @OtherCustomer_CustomerId IS NULL)))
AND @@ROWCOUNT > 0

DELETE [dbo].[Orders]
WHERE ((((((([order_id] = @xid) AND ([Key] = @key_for_delete)) AND ([Code] = @Code)) AND ([Signature] = @Signature)) AND (([Name] = @Name_Original) OR ([Name] IS NULL AND @Name_Original IS NULL))) AND (([RowVersion] = @RowVersion_Original) OR ([RowVersion] IS NULL AND @RowVersion_Original IS NULL))) AND (([Customer_CustomerId] = @Customer_CustomerId) OR ([Customer_CustomerId] IS NULL AND @Customer_CustomerId IS NULL)))
AND @@ROWCOUNT > 0

SET @rows_affected = @@ROWCOUNT",
                functionSqlGenerator.GenerateDelete(convertedTrees, "rows_affected"));
        }
        public void Delete_simple_entity()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Customer");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                    .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                    modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                    .Convert(commandTrees)
                    .OfType<DbDeleteCommandTree>()
                    .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(new SqlGenerator());

            Assert.Equal(
                @"DELETE [dbo].[Customers]
WHERE ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateDelete(convertedTrees, null));
        }
        public void Delete_tpt_entity_with_concurrency_and_store_generated_values()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                    .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                    modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                    .Convert(commandTrees)
                    .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"delete [dbo].[xspecial_orders]
where (((([xid] = @xid) and ([so_key] = @key_for_delete)) and ([Code] = @Code)) and ([Signature] = @Signature))

delete [dbo].[special_orders]
where ((((([order_id] = @xid) and ([so_key] = @key_for_delete)) and ([Code] = @Code)) and ([Signature] = @Signature)) and (([OtherCustomer_CustomerId] = @OtherCustomer_CustomerId) or ([OtherCustomer_CustomerId] is null and @OtherCustomer_CustomerId is null)))
and @@ROWCOUNT > 0

delete [dbo].[Orders]
where ((((((([order_id] = @xid) and ([Key] = @key_for_delete)) and ([Code] = @Code)) and ([Signature] = @Signature)) and (([Name] = @Name_Original) or ([Name] is null and @Name_Original is null))) and (([RowVersion] = @RowVersion_Original) or ([RowVersion] is null and @RowVersion_Original is null))) and (([Customer_CustomerId] = @Customer_CustomerId) or ([Customer_CustomerId] is null and @Customer_CustomerId is null)))
and @@ROWCOUNT > 0

set @rows_affected = @@ROWCOUNT",
                functionSqlGenerator.GenerateDelete(convertedTrees, "rows_affected"));
        }
        public void Delete_simple_entity()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Customer");

            var commandTrees
                = new ModificationCommandTreeGenerator(TestContext.CreateDynamicUpdateModel())
                    .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            var convertedTrees
                = new DynamicToFunctionModificationCommandConverter(
                    modificationFunctionMapping.Item1, modificationFunctionMapping.Item2)
                    .Convert(commandTrees)
                    .ToList();

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"delete [dbo].[Customers]
where ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateDelete(convertedTrees, null));
        }