本文整理汇总了C#中EntitySet.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# EntitySet.Remove方法的具体用法?C# EntitySet.Remove怎么用?C# EntitySet.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntitySet
的用法示例。
在下文中一共展示了EntitySet.Remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListChanged_WithSource
public void ListChanged_WithSource()
{
// When is ListChanged emitted?
// It's not always when you think it would be.
var people = new EntitySet<Person>();
var events = new List<ListChangedEventArgs>();
people.ListChanged += (o, e) => events.Add(e);
// This is also true if Enumerable.Empty<Person>() is used here.
people.SetSource(new[]{
new Person { FirstName = "(", LastName = ")" },
});
AssertEqual(events);
Assert.IsTrue(people.IsDeferred);
// *Initial* Add()/AddRange() is ignored.
people.Add(new Person { FirstName = "A", LastName = "B" });
people.AddRange(new[]{
new Person { FirstName = "1", LastName = "2" },
new Person { FirstName = "<", LastName = ">" },
});
Assert.IsTrue(people.HasLoadedOrAssignedValues);
Assert.IsTrue(people.IsDeferred);
AssertEqual(events);
events.Clear();
people.Clear();
AssertEqual(events,
new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
new ListChangedEventArgs(ListChangedType.Reset, 0, -1));
Assert.IsFalse(people.IsDeferred);
// Add()/AddRange() after a Clear has events.
events.Clear();
people.Add(new Person { FirstName = "A", LastName = "B" });
people.AddRange(new[]{
new Person { FirstName = "1", LastName = "2" },
new Person { FirstName = "<", LastName = ">" },
});
AssertEqual(events,
new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1),
new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1),
new ListChangedEventArgs(ListChangedType.ItemAdded, 2, -1));
events.Clear();
var p = new Person { FirstName = "{", LastName = "}" };
people.Insert(1, p);
AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1));
events.Clear();
Assert.IsTrue(people.Remove(p));
AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 1, -1));
events.Clear();
people.RemoveAt(0);
AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1));
events.Clear();
people[0] = p;
AssertEqual(events,
new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1));
}
示例2: Remove
public void Remove()
{
var people = new EntitySet<Person>();
var events = new List<ListChangedEventArgs>();
people.ListChanged += (o, e) => events.Add(e);
people.SetSource(new[]{
new Person { FirstName = "(", LastName = ")" },
});
Assert.IsTrue(people.IsDeferred);
Assert.IsFalse(people.Remove(null));
AssertEqual(events);
events.Clear();
Assert.IsTrue(people.IsDeferred);
var p = people[0];
Assert.IsTrue(people.Remove(p));
Assert.IsFalse(people.IsDeferred);
Assert.AreEqual(0, people.Count);
AssertEqual(events,
new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1));
}
示例3: ListChanged_NoSource
public void ListChanged_NoSource()
{
// When is ListChanged emitted?
// It's not always when you think it would be.
// It depends on whether there's a Source present.
var people = new EntitySet<Person>();
var events = new List<ListChangedEventArgs> ();
people.ListChanged += (o, e) => events.Add(e);
people.Add(new Person { FirstName = "A", LastName = "B" });
AssertEqual(events);
events.Clear();
people.Clear();
AssertEqual(events, new ListChangedEventArgs(ListChangedType.Reset, 0, -1));
events.Clear();
people.AddRange(new[]{
new Person { FirstName = "1", LastName = "2" },
new Person { FirstName = "<", LastName = ">" },
});
AssertEqual(events);
events.Clear();
var p = new Person { FirstName = "{", LastName = "}" };
people.Insert(1, p);
AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1));
events.Clear();
Assert.IsTrue(people.Remove(p));
AssertEqual(events);
events.Clear();
people.RemoveAt(0);
AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1));
events.Clear();
people[0] = p;
AssertEqual(events,
new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1));
}