当前位置: 首页>>代码示例>>C#>>正文


C# TestDbContext.UpdateGraph方法代码示例

本文整理汇总了C#中TestDbContext.UpdateGraph方法的典型用法代码示例。如果您正苦于以下问题:C# TestDbContext.UpdateGraph方法的具体用法?C# TestDbContext.UpdateGraph怎么用?C# TestDbContext.UpdateGraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestDbContext的用法示例。


在下文中一共展示了TestDbContext.UpdateGraph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldAddNewAggregateRoot_Attached

        public void ShouldAddNewAggregateRoot_Attached()
        {
            var associated = new OneToOneAssociatedModel { Title = "Associated" };
            var manyAssociated = new OneToManyAssociatedModel { Title = "Associated" };
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyOwned = new List<OneToManyOwnedModel>
                {
                    new OneToManyOwnedModel { Title = "One" },
                    new OneToManyOwnedModel { Title = "Two" },
                    new OneToManyOwnedModel { Title = "Three" }
                },
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    manyAssociated
                },
                OneToOneOwned = new OneToOneOwnedModel { Title = "OneToOne" },
                OneToOneAssociated = associated
            };

            using (var context = new TestDbContext())
            {
                context.OneToManyAssociatedModels.Add(manyAssociated);
                context.OneToOneAssociatedModels.Add(associated);

                     node1 = context.UpdateGraph(node1);

                context.SaveChanges();
                Assert.IsNotNull(context.Nodes.SingleOrDefault(p => p.Id == node1.Id));
            }
        }
开发者ID:siegeon,项目名称:GraphDiff,代码行数:32,代码来源:AddAggregateBehaviours.cs

示例2: ShouldSupportGuidKeys

        public void ShouldSupportGuidKeys()
        {
            var model = new GuidTestNode();
            using (var context = new TestDbContext())
            {
                context.GuidKeyModels.Add(model);
                context.SaveChanges();

                // http://stackoverflow.com/questions/5270721/using-guid-as-pk-with-ef4-code-first
                Assert.IsTrue(Attribute.IsDefined(model.GetType().GetProperty("Id"), typeof(DatabaseGeneratedAttribute)));

                Assert.IsNotNull(model.Id);
                Assert.AreNotEqual(Guid.Empty, model.Id);
            } // simulate detach

            model.OneToOneOwned = new GuidOneToOneOwned();

            using (var context = new TestDbContext())
            {
                model = context.UpdateGraph(model, map => map.OwnedEntity(g => g.OneToOneOwned));
                context.SaveChanges();

                Assert.IsNotNull(model.OneToOneOwned);
                Assert.IsNotNull(model.OneToOneOwned.Id);
                Assert.AreNotEqual(Guid.Empty, model.OneToOneOwned.Id);
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:27,代码来源:GuidKeyBehaviors.cs

示例3: ShouldAddAssociatedWithoutChangingRequiredAssociate

        public void ShouldAddAssociatedWithoutChangingRequiredAssociate()
        {
            var root = new RootEntity { RequiredAssociate = new RequiredAssociate(), Sources = new List<RootEntity>() };
            var requiredAssociate = new RequiredAssociate();
            using (var context = new TestDbContext())
            {
                context.RootEntities.Add(root);
                context.RequiredAssociates.Add(requiredAssociate);
                context.SaveChanges();
            } // Simulate detach

            var expectedAssociateId = requiredAssociate.Id;
            var owned = new RootEntity { RequiredAssociate = requiredAssociate };
            root.Sources.Add(owned);

            using (var context = new TestDbContext())
            {
                root = context.UpdateGraph(root, map => map.AssociatedCollection(r => r.Sources));
                context.SaveChanges();

                var ownedAfterSave = root.Sources.FirstOrDefault();
                Assert.IsNotNull(ownedAfterSave);
                Assert.IsNotNull(ownedAfterSave.RequiredAssociate);
                Assert.AreEqual(expectedAssociateId, ownedAfterSave.RequiredAssociate.Id);

                var ownedReloaded = context.RootEntities.Single(r => r.Id == ownedAfterSave.Id);
                Assert.IsNotNull(ownedReloaded.RequiredAssociate);
                Assert.AreEqual(expectedAssociateId, ownedReloaded.RequiredAssociate.Id);
            }
        }
开发者ID:rklachko,项目名称:GraphDiff,代码行数:30,代码来源:AssociatedCollectionBehaviours.cs

示例4: ShouldSupportNullValuesInTree

        public void ShouldSupportNullValuesInTree()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToOneOwned = null
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            using (var context = new TestDbContext())
            {
                // Setup mapping
                node1 = context.UpdateGraph(node1, map => map
                    .OwnedEntity(p => p.OneToOneOwned, with =>
                        with.OwnedEntity(p => p.OneToOneOneToOneOwned)));

                context.SaveChanges();
                context.Entry(node1).Reload();
                Assert.IsTrue(node1.OneToOneOwned == null);
            }
        }
开发者ID:joswalt,项目名称:Highway.Data,代码行数:26,代码来源:ThirdTierBehaviours.cs

示例5: ShouldNotUpdateEntitesWithinAnAssociatedCollection

        public void ShouldNotUpdateEntitesWithinAnAssociatedCollection()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    new OneToManyAssociatedModel { Title = "First One" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToManyAssociated.First().Title = "This should not overwrite value";

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedCollection(p => p.OneToManyAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyAssociated.Single().Title == "First One");
            }
        }
开发者ID:GertArnold,项目名称:GraphDiff,代码行数:31,代码来源:AssociatedCollectionBehaviours.cs

示例6: ShouldNotUpdatePropertiesOfAnAssociatedEntity

        public void ShouldNotUpdatePropertiesOfAnAssociatedEntity()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToOneAssociated = new OneToOneAssociatedModel { Title = "Associated Node" }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneAssociated.Title = "Updated Content";

            using (var context = new TestDbContext())
            {
                context.UpdateGraph(node1);

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToOneAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToOneAssociated.OneParent == node2);
                // should not delete it as it is associated and no cascade rule set.
                Assert.IsTrue(node2.OneToOneAssociated.Title == "Associated Node");
            }
        }
开发者ID:siegeon,项目名称:GraphDiff,代码行数:28,代码来源:AssociatedEntityBehaviours.cs

示例7: ShouldAddRelationToExistingAssociatedCollection

        public void ShouldAddRelationToExistingAssociatedCollection()
        {
            var associated = new OneToManyAssociatedModel { Title = "Second One" };
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    new OneToManyAssociatedModel { Title = "First One" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.OneToManyAssociatedModels.Add(associated);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToManyAssociated.Add(associated);

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedCollection(p => p.OneToManyAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyAssociated.Count == 2);
            }
        }
开发者ID:GertArnold,项目名称:GraphDiff,代码行数:33,代码来源:AssociatedCollectionBehaviours.cs

示例8: ShouldBeAbleToVisitExpressionsStoredAsProperties

        public void ShouldBeAbleToVisitExpressionsStoredAsProperties()
        {
            var node1 = new TestNode
            {
                Title = "One",
                OneToOneOwned = new OneToOneOwnedModel { Title = "Hello" }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneOwned.Title = "Hey2";

            Lambda = (p => p.OneToOneOwned);
            Expression<Func<IUpdateConfiguration<TestNode>, dynamic>> exp = map => map.OwnedEntity(Lambda);

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, exp);

                context.SaveChanges();
                Assert.IsTrue(context.Nodes
                    .Include(p => p.OneToOneOwned)
                    .Single(p => p.Id == node1.Id)
                    .OneToOneOwned.Title == "Hey2");
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:31,代码来源:ConfigurationVisitorBehaviours.cs

示例9: ShouldAddRelationIfPreviousValueWasNullWithCycle

        public void ShouldAddRelationIfPreviousValueWasNullWithCycle()
        {
            GroupedTestNode two;
            GroupedTestNode one;
            using (var context = new TestDbContext())
            {
                var group = new NodeGroup();
                context.NodeGroups.Add(group);
                context.SaveChanges();

                one = new GroupedTestNode { Group = group };
                context.Nodes.Add(one);
                context.SaveChanges();

                two = new GroupedTestNode { Group = group };
                context.Nodes.Add(two);
                context.SaveChanges();

                Assert.AreEqual(2, group.Members.Count);
            } // Simulate detach

            using (var context = new TestDbContext())
            {
                one.Two = two;

                // Setup mapping
                context.UpdateGraph(one, map => map.AssociatedEntity(o => o.Two));
                context.SaveChanges();

                var oneReloaded = context.Nodes.OfType<GroupedTestNode>().Include("Two").Single(n => n.Id == one.Id);
                Assert.IsNotNull(oneReloaded.Two);
                Assert.AreEqual(two.Id, oneReloaded.Two.Id);
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:34,代码来源:AssociatedEntityBehaviours.cs

示例10: ShouldSupportMultipleKeys

        public void ShouldSupportMultipleKeys()
        {
            var model = new MultiKeyModel
            {
                Title = "Hello",
                Date = DateTime.Now,
                KeyPart1 = "A123",
                KeyPart2 = "A234"
            };

            using (var context = new TestDbContext())
            {
                context.MultiKeyModels.Add(model);
                context.SaveChanges();
            } // simulate detach

            model.Date = DateTime.Parse("01/01/2010");
            using (var context = new TestDbContext())
            {
                model = context.UpdateGraph(model);
                context.SaveChanges();

                context.Entry(model).Reload();
                Assert.IsTrue(model.Date == DateTime.Parse("01/01/2010"));
            }
        }
开发者ID:rklachko,项目名称:GraphDiff,代码行数:26,代码来源:MiscBehaviours.cs

示例11: ShouldAddRelationIfPreviousValueWasNull

        public void ShouldAddRelationIfPreviousValueWasNull()
        {
            var node1 = new TestNode { Title = "New Node" };
            var associated = new OneToOneAssociatedModel { Title = "Associated Node" };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.OneToOneAssociatedModels.Add(associated);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneAssociated = associated;

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedEntity(p => p.OneToOneAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToOneAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToOneAssociated.OneParent == node2);
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:26,代码来源:AssociatedEntityBehaviours.cs

示例12: ShouldThrowDbUpdateConcurrencyExceptionIfEditingNestedOutOfDateModel

        public void ShouldThrowDbUpdateConcurrencyExceptionIfEditingNestedOutOfDateModel()
        {
            TestNode node;
            using (var db = new TestDbContext())
            {
                node = new TestNode
                {
                    Title = "Hello",
                    OneToManyOwned = new List<OneToManyOwnedModel>
                    {
                        new OneToManyOwnedModel { Title = "Test1" },
                        new OneToManyOwnedModel { Title = "Test2" }
                    }
                };
                db.Nodes.Add(node);
                db.SaveChanges();
            }

            using (var db = new TestDbContext())
            {
                node.OneToManyOwned.First().RowVersion = new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 };
                db.UpdateGraph(node, map => map.OwnedCollection(p => p.OneToManyOwned));
                db.SaveChanges();
            }
        }
开发者ID:joswalt,项目名称:Highway.Data,代码行数:25,代码来源:OptimisticConcurrencyBehaviours.cs

示例13: ShouldAddNewItemInOwnedCollection

        public void ShouldAddNewItemInOwnedCollection()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyOwned = new List<OneToManyOwnedModel>
                {
                    new OneToManyOwnedModel { Title = "Hello" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            var newModel = new OneToManyOwnedModel { Title = "Hi" };
            node1.OneToManyOwned.Add(newModel);
            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .OwnedCollection(p => p.OneToManyOwned));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyOwned).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyOwned.Count == 2);
                var owned = context.OneToManyOwnedModels.Single(p => p.Id == newModel.Id);
                Assert.IsTrue(owned.OneParent == node2 && owned.Title == "Hi");
            }
        }
开发者ID:GertArnold,项目名称:GraphDiff,代码行数:33,代码来源:OwnedCollectionBehaviours.cs

示例14: ShouldThrowIfTypeIsNotKnown

 public void ShouldThrowIfTypeIsNotKnown()
 {
     using (var context = new TestDbContext())
     {
         context.UpdateGraph(new UnknownType());
         context.SaveChanges();
     }
 }
开发者ID:rho24,项目名称:GraphDiff,代码行数:8,代码来源:ErrorHandlingBehaviours.cs

示例15: ShouldSupportInternalKeys

        public void ShouldSupportInternalKeys()
        {
            using (var context = new TestDbContext())
            {
                var model = context.UpdateGraph(new InternalKeyModel());
                context.SaveChanges();

                Assert.AreNotEqual(0, model.Id);
            }
        }
开发者ID:rklachko,项目名称:GraphDiff,代码行数:10,代码来源:MiscBehaviours.cs


注:本文中的TestDbContext.UpdateGraph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。