本文整理汇总了C#中ChangeSet.GetOriginal方法的典型用法代码示例。如果您正苦于以下问题:C# ChangeSet.GetOriginal方法的具体用法?C# ChangeSet.GetOriginal怎么用?C# ChangeSet.GetOriginal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChangeSet
的用法示例。
在下文中一共展示了ChangeSet.GetOriginal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Changeset_OriginalInvalidForInserts
public void Changeset_OriginalInvalidForInserts()
{
// can't specify an original for an insert operation
Product curr = new Product { ProductID = 1 };
Product orig = new Product { ProductID = 1 };
ChangeSetEntry entry = new ChangeSetEntry { Id = 1, Entity = curr, OriginalEntity = orig, Operation = ChangeOperation.Insert };
ChangeSet cs = null;
Assert.Throws<InvalidOperationException>(delegate
{
cs = new ChangeSet(new ChangeSetEntry[] { entry });
},
String.Format(Resource.InvalidChangeSet, Resource.InvalidChangeSet_InsertsCantHaveOriginal));
// get original should throw for insert operations
entry = new ChangeSetEntry { Id = 1, Entity = curr, OriginalEntity = null, Operation = ChangeOperation.Insert };
cs = new ChangeSet(new ChangeSetEntry[] { entry });
Assert.Throws<InvalidOperationException>(delegate
{
cs.GetOriginal(curr);
},
String.Format(Resource.ChangeSet_OriginalNotValidForInsert));
}
示例2: Changeset_OriginalInvalidForInserts
public void Changeset_OriginalInvalidForInserts()
{
// can't specify an original for an insert operation
TimestampEntityA curr = new TimestampEntityA { ID = 1, Version = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }, ValueA = "Foo", ValueB = "Bar" } ;
TimestampEntityA orig = new TimestampEntityA { ID = 1, Version = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }, ValueA = "x", ValueB = "x" };
ChangeSetEntry entry = new ChangeSetEntry(1, curr, orig, DomainOperation.Insert);
ChangeSet cs = null;
ExceptionHelper.ExpectInvalidOperationException(delegate
{
cs = new ChangeSet(new ChangeSetEntry[] { entry });
},
string.Format(Resource.InvalidChangeSet, Resource.InvalidChangeSet_InsertsCantHaveOriginal));
// get original should throw for insert operations
entry = new ChangeSetEntry(1, curr, null, DomainOperation.Insert);
cs = new ChangeSet(new ChangeSetEntry[] { entry });
ExceptionHelper.ExpectInvalidOperationException(delegate
{
cs.GetOriginal(curr);
},
string.Format(Resource.ChangeSet_OriginalNotValidForInsert));
}
示例3: 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));
}