public void Can_generate_update_tree_when_table_splitting_dependent() { DbModel model; using (var context = new TableSplittingContext()) { model = context .InternalContext .CodeFirstModel .CachedModelBuilder .BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo); } var commandTreeGenerator = new ModificationCommandTreeGenerator(model); var commandTrees = commandTreeGenerator .GenerateUpdate(GetType().Namespace + ".StandingStone") .ToList(); Assert.Equal(1, commandTrees.Count()); Assert.IsType <DbUpdateCommandTree>(commandTrees.Single()); }
public void Can_generate_dynamic_update_command_trees() { var model = TestContext.CreateDynamicUpdateModel(); var commandTreeGenerator = new ModificationCommandTreeGenerator(model); var commandTrees = commandTreeGenerator .GenerateUpdate(GetType().Namespace + ".FunctionsModel.SpecialOrder") .ToList(); Assert.Equal(2, commandTrees.Count()); var commandTree = (DbUpdateCommandTree)commandTrees.First(); Assert.Equal(6, commandTree.SetClauses.Count); Assert.NotNull(commandTree.Predicate); Assert.NotNull(commandTree.Returning); Assert.Equal("Order", commandTree.Target.VariableType.EdmType.Name); commandTree = (DbUpdateCommandTree)commandTrees.Last(); Assert.Equal(4, commandTree.SetClauses.Count); Assert.NotNull(commandTree.Predicate); Assert.NotNull(commandTree.Returning); Assert.Equal("special_orders", commandTree.Target.VariableType.EdmType.Name); commandTrees = commandTreeGenerator .GenerateUpdate(GetType().Namespace + ".FunctionsModel.Customer") .ToList(); Assert.Equal(1, commandTrees.Count()); commandTree = (DbUpdateCommandTree)commandTrees.Single(); Assert.Equal(1, commandTree.SetClauses.Count); Assert.Equal("Customer", commandTree.Target.VariableType.EdmType.Name); Assert.Null(commandTree.Returning); }
public void Can_generate_update_tree_when_self_ref_direct() { DbModel model; using (var context = new WorldContext_Identity()) { model = context.InternalContext.CodeFirstModel.CachedModelBuilder.BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo); } var commandTreeGenerator = new ModificationCommandTreeGenerator(model); var commandTrees = commandTreeGenerator.GenerateUpdate(GetType().Namespace + ".Thing").ToList(); Assert.Equal(1, commandTrees.Count()); }
public void Can_convert_update_command_trees() { var model = TestContext.CreateDynamicUpdateModel(); var modificationFunctionMapping = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder"); var converter = new DynamicToFunctionModificationCommandConverter( modificationFunctionMapping.Item1, modificationFunctionMapping.Item2); var modificationCommandTreeGenerator = new ModificationCommandTreeGenerator(model); var commandTrees = modificationCommandTreeGenerator .GenerateUpdate(modificationFunctionMapping.Item1.EntityType.FullName); Assert.Equal(3, commandTrees.Count()); var resultTrees = converter.Convert(commandTrees); Assert.Equal(3, resultTrees.Count()); var firstCommandTree = (DbUpdateCommandTree)resultTrees.First(); Assert.Equal(12, firstCommandTree.Parameters.Count()); Assert.Equal(6, firstCommandTree.SetClauses.Count()); Assert.Equal("Name", firstCommandTree.Parameters.ElementAt(0).Key); Assert.Equal("Address_Street", firstCommandTree.Parameters.ElementAt(1).Key); Assert.Equal("Address_City", firstCommandTree.Parameters.ElementAt(2).Key); Assert.Equal("Address_CountryOrRegion_Name", firstCommandTree.Parameters.ElementAt(3).Key); Assert.Equal("OrderGroupId", firstCommandTree.Parameters.ElementAt(4).Key); Assert.Equal("Customer_CustomerId", firstCommandTree.Parameters.ElementAt(5).Key); Assert.Equal("xid", firstCommandTree.Parameters.ElementAt(6).Key); Assert.Equal("key_for_update", firstCommandTree.Parameters.ElementAt(7).Key); Assert.Equal("Code", firstCommandTree.Parameters.ElementAt(8).Key); Assert.Equal("Signature", firstCommandTree.Parameters.ElementAt(9).Key); Assert.Equal("Name_Original", firstCommandTree.Parameters.ElementAt(10).Key); Assert.Equal("RowVersion_Original", firstCommandTree.Parameters.ElementAt(11).Key); var properties = ((RowType)firstCommandTree.Returning.ResultType.EdmType).Properties; Assert.Equal(2, properties.Count); Assert.Equal("order_fu", properties[0].Name); }
public void Can_generate_update_tree_when_one_to_one_ia() { DbModel model; using (var context = new GearsOfWarContextSPBug()) { model = context .InternalContext .CodeFirstModel .CachedModelBuilder .BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo); } var commandTreeGenerator = new ModificationCommandTreeGenerator(model); var commandTrees = commandTreeGenerator .GenerateUpdate(GetType().Namespace + ".Gear") .ToList(); Assert.Equal(1, commandTrees.Count()); }