Beispiel #1
0
        public void Update_simple_entity()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Customer");

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

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

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

            Assert.Equal(
                @"UPDATE [dbo].[Customers]
SET [Name] = @Name
WHERE ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateUpdate(convertedTrees, null));
        }
        public void Update_value_type_concurrency_token()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Person");

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

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

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

            Assert.Equal(
                @"UPDATE [dbo].[People]
SET [BirthDate] = @BirthDate
WHERE (([Id] = @Id) AND ([BirthDate] = @BirthDate_Original))",
                functionSqlGenerator.GenerateUpdate(convertedTrees, null));
        }
Beispiel #3
0
        public void Update_tpt_entity_with_concurrency_and_store_generated_values()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder");

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

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

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

            Assert.Equal(
                @"UPDATE [dbo].[Orders]
SET [Name] = @Name, [Address_Street] = @Address_Street, [Address_City] = @Address_City, [Address_Country_Name] = @Address_Country_Name, [OrderGroupId] = @OrderGroupId, [Customer_CustomerId] = @Customer_CustomerId
WHERE (((((([order_id] = @xid) AND ([Key] = @key_for_update)) 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)))

UPDATE [dbo].[special_orders]
SET [OtherCustomer_CustomerId] = @OtherCustomer_CustomerId, [OtherAddress_Street] = @OtherAddress_Street, [OtherAddress_City] = @OtherAddress_City, [OtherAddress_Country_Name] = @OtherAddress_Country_Name
WHERE (((([order_id] = @xid) AND ([so_key] = @key_for_update)) AND ([Code] = @Code)) AND ([Signature] = @Signature))
AND @@ROWCOUNT > 0

UPDATE [dbo].[xspecial_orders]
SET [TheSpecialist] = @TheSpecialist
WHERE (((([xid] = @xid) AND ([so_key] = @key_for_update)) AND ([Code] = @Code)) AND ([Signature] = @Signature))
AND @@ROWCOUNT > 0

SELECT t0.[OrderNo] AS order_fu, t0.[RowVersion], t1.[MagicOrderToken], t2.[FairyDust]
FROM [dbo].[Orders] AS t0
JOIN [dbo].[special_orders] AS t1 ON t1.[order_id] = t0.[order_id] AND t1.[so_key] = t0.[Key] AND t1.[Code] = t0.[Code] AND t1.[Signature] = t0.[Signature]
JOIN [dbo].[xspecial_orders] AS t2 ON t2.[xid] = t0.[order_id] AND t2.[so_key] = t0.[Key] AND t2.[Code] = t0.[Code] AND t2.[Signature] = t0.[Signature]
WHERE @@ROWCOUNT > 0 AND t0.[order_id] = @xid AND t0.[Key] = @key_for_update AND t0.[Code] = @Code AND t0.[Signature] = @Signature

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

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

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

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"update [dbo].[Orders]
set [Name] = @Name, [Address_Street] = @Address_Street, [Address_City] = @Address_City, [Address_Country_Name] = @Address_Country_Name, [OrderGroupId] = @OrderGroupId, [Customer_CustomerId] = @Customer_CustomerId
where ((((((([order_id] = @xid) and ([Key] = @key_for_update)) 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)))

update [dbo].[special_orders]
set [OtherCustomer_CustomerId] = @OtherCustomer_CustomerId, [OtherAddress_Street] = @OtherAddress_Street, [OtherAddress_City] = @OtherAddress_City, [OtherAddress_Country_Name] = @OtherAddress_Country_Name
where ((((([order_id] = @xid) and ([so_key] = @key_for_update)) and ([Code] = @Code)) and ([Signature] = @Signature)) and (([OtherCustomer_CustomerId] = @OtherCustomer_CustomerId) or ([OtherCustomer_CustomerId] is null and @OtherCustomer_CustomerId is null)))
and @@ROWCOUNT > 0

update [dbo].[xspecial_orders]
set [TheSpecialist] = @TheSpecialist
where (((([xid] = @xid) and ([so_key] = @key_for_update)) and ([Code] = @Code)) and ([Signature] = @Signature))
and @@ROWCOUNT > 0

select t0.[OrderNo] as order_fu, t0.[RowVersion], t1.[MagicOrderToken], t2.[FairyDust]
from [dbo].[Orders] as t0
join [dbo].[special_orders] as t1 on t1.[order_id] = t0.[order_id] and t1.[so_key] = t0.[Key] and t1.[Code] = t0.[Code] and t1.[Signature] = t0.[Signature]
join [dbo].[xspecial_orders] as t2 on t2.[xid] = t0.[order_id] and t2.[so_key] = t0.[Key] and t2.[Code] = t0.[Code] and t2.[Signature] = t0.[Signature]
where @@ROWCOUNT > 0 and t0.[order_id] = @xid and t0.[Key] = @key_for_update and t0.[Code] = @Code and t0.[Signature] = @Signature

set @rows_affected = @@ROWCOUNT",
                functionSqlGenerator.GenerateUpdate(convertedTrees, "rows_affected"));
        }
Beispiel #5
0
        public void Update_simple_entity_with_tph_base()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Vehicle");

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

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

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

            Assert.Null(functionSqlGenerator.GenerateUpdate(convertedTrees, null));
        }
        public void Update_simple_entity()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Customer");

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

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

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"update [dbo].[Customers]
set [Name] = @Name
where ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateUpdate(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 Update_simple_entity_with_tph_base()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Vehicle");

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

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

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

            Assert.Null(functionSqlGenerator.GenerateUpdate(convertedTrees, null));
        }
        public void Update_value_type_concurrency_token()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Person");

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

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

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

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

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

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

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

            Assert.Equal(
                @"UPDATE [dbo].[Orders]
SET [Name] = @Name, [Address_Street] = @Address_Street, [Address_City] = @Address_City, [Address_CountryOrRegion_Name] = @Address_CountryOrRegion_Name, [OrderGroupId] = @OrderGroupId, [Customer_CustomerId] = @Customer_CustomerId
WHERE (((((([order_id] = @xid) AND ([Key] = @key_for_update)) 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)))

UPDATE [dbo].[special_orders]
SET [OtherCustomer_CustomerId] = @OtherCustomer_CustomerId, [OtherAddress_Street] = @OtherAddress_Street, [OtherAddress_City] = @OtherAddress_City, [OtherAddress_CountryOrRegion_Name] = @OtherAddress_CountryOrRegion_Name
WHERE (((([order_id] = @xid) AND ([so_key] = @key_for_update)) AND ([Code] = @Code)) AND ([Signature] = @Signature))
AND @@ROWCOUNT > 0

UPDATE [dbo].[xspecial_orders]
SET [TheSpecialist] = @TheSpecialist
WHERE (((([xid] = @xid) AND ([so_key] = @key_for_update)) AND ([Code] = @Code)) AND ([Signature] = @Signature))
AND @@ROWCOUNT > 0

SELECT t0.[OrderNo] AS order_fu, t0.[RowVersion], t1.[MagicOrderToken], t2.[FairyDust]
FROM [dbo].[Orders] AS t0
JOIN [dbo].[special_orders] AS t1 ON t1.[order_id] = t0.[order_id] AND t1.[so_key] = t0.[Key] AND t1.[Code] = t0.[Code] AND t1.[Signature] = t0.[Signature]
JOIN [dbo].[xspecial_orders] AS t2 ON t2.[xid] = t0.[order_id] AND t2.[so_key] = t0.[Key] AND t2.[Code] = t0.[Code] AND t2.[Signature] = t0.[Signature]
WHERE @@ROWCOUNT > 0 AND t0.[order_id] = @xid AND t0.[Key] = @key_for_update AND t0.[Code] = @Code AND t0.[Signature] = @Signature

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

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

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

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

            Assert.Equal(
                @"UPDATE [dbo].[Customers]
SET [Name] = @Name
WHERE ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateUpdate(convertedTrees, null));
        }
        public void Update_simple_entity()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("Customer");

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

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

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"update [dbo].[Customers]
set [Name] = @Name
where ([CustomerId] = @CustomerId)",
                functionSqlGenerator.GenerateUpdate(convertedTrees, null));
        }
        public void Update_tpt_entity_with_concurrency_and_store_generated_values()
        {
            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder");

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

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

            var functionSqlGenerator
                = new DmlFunctionSqlGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal(
                @"update [dbo].[Orders]
set [Name] = @Name, [Address_Street] = @Address_Street, [Address_City] = @Address_City, [Address_Country_Name] = @Address_Country_Name, [OrderGroupId] = @OrderGroupId, [Customer_CustomerId] = @Customer_CustomerId
where ((((((([order_id] = @xid) and ([Key] = @key_for_update)) 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)))

update [dbo].[special_orders]
set [OtherCustomer_CustomerId] = @OtherCustomer_CustomerId, [OtherAddress_Street] = @OtherAddress_Street, [OtherAddress_City] = @OtherAddress_City, [OtherAddress_Country_Name] = @OtherAddress_Country_Name
where ((((([order_id] = @xid) and ([so_key] = @key_for_update)) and ([Code] = @Code)) and ([Signature] = @Signature)) and (([OtherCustomer_CustomerId] = @OtherCustomer_CustomerId) or ([OtherCustomer_CustomerId] is null and @OtherCustomer_CustomerId is null)))
and @@ROWCOUNT > 0

update [dbo].[xspecial_orders]
set [TheSpecialist] = @TheSpecialist
where (((([xid] = @xid) and ([so_key] = @key_for_update)) and ([Code] = @Code)) and ([Signature] = @Signature))
and @@ROWCOUNT > 0

select t0.[OrderNo] as order_fu, t0.[RowVersion], t1.[MagicOrderToken], t2.[FairyDust]
from [dbo].[Orders] as t0
join [dbo].[special_orders] as t1 on t1.[order_id] = t0.[order_id] and t1.[so_key] = t0.[Key] and t1.[Code] = t0.[Code] and t1.[Signature] = t0.[Signature]
join [dbo].[xspecial_orders] as t2 on t2.[xid] = t0.[order_id] and t2.[so_key] = t0.[Key] and t2.[Code] = t0.[Code] and t2.[Signature] = t0.[Signature]
where @@ROWCOUNT > 0 and t0.[order_id] = @xid and t0.[Key] = @key_for_update and t0.[Code] = @Code and t0.[Signature] = @Signature

set @rows_affected = @@ROWCOUNT",
                functionSqlGenerator.GenerateUpdate(convertedTrees, "rows_affected"));
        }