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


C# ChangeSet.GetChangeOperation方法代码示例

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


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

示例1: Changeset_GetAssociatedChanges_Enumerable

        public void Changeset_GetAssociatedChanges_Enumerable()
        {
            DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(CompositionScenarios_Explicit));

            #region build up a compositional hierarchy
            int id = 1;
            Parent currParent = new Parent();
            List<ChangeSetEntry> changeSetEntries = new List<ChangeSetEntry>();
            ChangeSetEntry parentUpdateOperation = new ChangeSetEntry(id++, currParent, null, DomainOperation.Update);
            List<int> currentAssociatedChildren = new List<int>();
            changeSetEntries.Add(parentUpdateOperation);

            // add 3 unmodified children
            List<Child> unmodifiedChildren = new List<Child>() { new Child(), new Child(), new Child() };
            foreach (Child c in unmodifiedChildren)
            {
                ChangeSetEntry operation = new ChangeSetEntry(id++, c, c, DomainOperation.None);
                changeSetEntries.Add(operation);
                currParent.Children.Add(c);
                currentAssociatedChildren.Add(operation.Id);
            }

            // add 2 child edits
            List<Child> originalEditedChildren = new List<Child> { new Child(), new Child() };
            List<Child> currentEditedChildren = new List<Child> { new Child(), new Child() };
            for (int i = 0; i < originalEditedChildren.Count; i++)
            {
                Child currChild = currentEditedChildren[i];
                Child origChild = originalEditedChildren[i];
                ChangeSetEntry operation = new ChangeSetEntry(id++, currChild, origChild, DomainOperation.Update);
                changeSetEntries.Add(operation);
                currParent.Children.Add(currChild);
                currentAssociatedChildren.Add(operation.Id);
            }

            // add a 2 new children children
            List<Child> newChildren = new List<Child> { new Child(), new Child() };
            foreach (Child c in newChildren)
            {
                ChangeSetEntry operation = new ChangeSetEntry(id++, c, null, DomainOperation.Insert);
                changeSetEntries.Add(operation);
                currParent.Children.Add(c);
                currentAssociatedChildren.Add(operation.Id);
            }

            // add 2 removes by adding operations for the deleted children
            // and setting up the original association
            List<Child> removedChildren = new List<Child> { new Child(), new Child() };
            List<int> deletedChildren = new List<int>();
            foreach (Child c in removedChildren)
            {
                int deletedId = id++;
                changeSetEntries.Add(new ChangeSetEntry(deletedId, c, c, DomainOperation.Delete));
                deletedChildren.Add(deletedId);
            }
            parentUpdateOperation.OriginalAssociations = new Dictionary<string, int[]>() { { "Children", deletedChildren.ToArray() } };
            parentUpdateOperation.Associations = new Dictionary<string, int[]>() { { "Children", currentAssociatedChildren.ToArray() } };
            #endregion

            // verify unmodified children
            ChangeSet cs = new ChangeSet(changeSetEntries);
            IEnumerable<Child> childChanges = cs.GetAssociatedChanges(currParent, p => p.Children, ChangeOperation.None).Cast<Child>();
            Assert.AreEqual(3, childChanges.Count());
            foreach (Child c in childChanges)
            {
                Assert.IsTrue(unmodifiedChildren.Contains(c));
            }

            // verify inserted children
            childChanges = cs.GetAssociatedChanges(currParent, p => p.Children, ChangeOperation.Insert).Cast<Child>();
            Assert.AreEqual(2, childChanges.Count());
            foreach (Child c in childChanges)
            {
                Assert.IsTrue(newChildren.Contains(c));
            }

            // verify deleted children
            childChanges = cs.GetAssociatedChanges(currParent, p => p.Children, ChangeOperation.Delete).Cast<Child>();
            Assert.AreEqual(2, childChanges.Count());
            foreach (Child c in childChanges)
            {
                Assert.IsTrue(removedChildren.Contains(c));
            }

            // verify modified children
            childChanges = cs.GetAssociatedChanges(currParent, p => p.Children, ChangeOperation.Update).Cast<Child>();
            Assert.AreEqual(2, childChanges.Count());
            foreach (Child c in childChanges)
            {
                Assert.IsTrue(currentEditedChildren.Contains(c));
            }

            // verify overload that returns all - should return all unmodified
            // in addition to all changed
            IEnumerable<Child> allChildren = cs.GetAssociatedChanges(currParent, p => p.Children).Cast<Child>();
            Assert.AreEqual(9, allChildren.Count());
            foreach (Child c in allChildren)
            {
                ChangeOperation operationType = cs.GetChangeOperation(c);
                switch (operationType)
//.........这里部分代码省略.........
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:101,代码来源:ChangeSetTests.cs

示例2: Changeset_GetAssociatedChanges_Singleton

        public void Changeset_GetAssociatedChanges_Singleton()
        {
            DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(CompositionScenarios_Explicit));

            // verify singleton change of None
            GreatGrandChild unmodifiedGgc = new GreatGrandChild();
            GrandChild currGrandChild = new GrandChild
            {
                Child = unmodifiedGgc
            };
            GrandChild origGrandChild = new GrandChild
            {
                Child = unmodifiedGgc
            };
            ChangeSetEntry gcOperation = new ChangeSetEntry(1, currGrandChild, origGrandChild, DomainOperation.Update);
            gcOperation.Associations = new Dictionary<string, int[]> { { "Child", new int[] { 2 } } };
            ChangeSetEntry ggcOperation = new ChangeSetEntry(2, unmodifiedGgc, null, DomainOperation.None);
            ChangeSet cs = new ChangeSet(new ChangeSetEntry[] { gcOperation, ggcOperation });
            GreatGrandChild ggcChange = cs.GetAssociatedChanges(currGrandChild, p => p.Child, ChangeOperation.None).Cast<GreatGrandChild>().SingleOrDefault();
            Assert.AreSame(unmodifiedGgc, ggcChange);

            // verify singleton insert
            GreatGrandChild newGgc = new GreatGrandChild();
            currGrandChild = new GrandChild
            {
                Child = newGgc
            };
            origGrandChild = new GrandChild
            {
                Child = null
            };
            gcOperation = new ChangeSetEntry(1, currGrandChild, origGrandChild, DomainOperation.Update);
            gcOperation.Associations = new Dictionary<string, int[]> { { "Child", new int[] { 2 } } };
            ggcOperation = new ChangeSetEntry(2, newGgc, null, DomainOperation.Insert);
            cs = new ChangeSet(new ChangeSetEntry[] { gcOperation, ggcOperation });
            ggcChange = cs.GetAssociatedChanges(currGrandChild, p => p.Child, ChangeOperation.Insert).Cast<GreatGrandChild>().SingleOrDefault();
            Assert.AreSame(newGgc, ggcChange);
            Assert.AreEqual(ChangeOperation.Insert, cs.GetChangeOperation(newGgc));

            // verify singleton update
            GreatGrandChild modifiedGgc = new GreatGrandChild();
            currGrandChild = new GrandChild
            {
                Child = modifiedGgc
            };
            origGrandChild = new GrandChild
            {
                Child = modifiedGgc
            };
            gcOperation = new ChangeSetEntry(1, currGrandChild, origGrandChild, DomainOperation.Update);
            gcOperation.Associations = new Dictionary<string, int[]> { { "Child", new int[] { 2 } } };
            ggcOperation = new ChangeSetEntry(2, modifiedGgc, unmodifiedGgc, DomainOperation.Update);
            cs = new ChangeSet(new ChangeSetEntry[] { gcOperation, ggcOperation });
            ggcChange = cs.GetAssociatedChanges(currGrandChild, p => p.Child, ChangeOperation.Update).Cast<GreatGrandChild>().SingleOrDefault();
            Assert.AreSame(modifiedGgc, ggcChange);
            Assert.AreSame(unmodifiedGgc, cs.GetOriginal(modifiedGgc));
            Assert.AreEqual(ChangeOperation.Update, cs.GetChangeOperation(modifiedGgc));

            // verify singleton delete
            GreatGrandChild deletedGgc = new GreatGrandChild();
            currGrandChild = new GrandChild
            {
                Child = null
            };
            origGrandChild = new GrandChild
            {
                Child = deletedGgc
            };
            gcOperation = new ChangeSetEntry(1, currGrandChild, null, DomainOperation.Update);
            gcOperation.OriginalAssociations = new Dictionary<string, int[]>() { { "Child", new int[] { 2 } } };
            ggcOperation = new ChangeSetEntry(2, deletedGgc, null, DomainOperation.Delete);
            gcOperation.OriginalAssociations = new Dictionary<string, int[]>() { { "Child", new int[] { 2 } } };
            cs = new ChangeSet(new ChangeSetEntry[] { gcOperation, ggcOperation });
            ggcChange = cs.GetAssociatedChanges(currGrandChild, p => p.Child, ChangeOperation.Delete).Cast<GreatGrandChild>().SingleOrDefault();
            Assert.AreSame(deletedGgc, ggcChange);
            Assert.AreSame(null, cs.GetOriginal(deletedGgc));
            Assert.AreEqual(ChangeOperation.Delete, cs.GetChangeOperation(deletedGgc));
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:78,代码来源:ChangeSetTests.cs


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