LocalView<TEntity> LocalView(Of TEntity) Class

Definition

A collection that stays in sync with entities of a given type being tracked by a DbContext. Call Local to obtain a local view.

This local view will stay in sync as entities are added or removed from the context. Likewise, entities added to or removed from the local view will automatically be added to or removed from the context.

Adding an entity to this collection will cause it to be tracked in the Added state by the context unless it is already being tracked.

Removing an entity from this collection will cause it to be marked as Deleted, unless it was previously in the Added state, in which case it will be detached from the context.

The collection implements , , and such that notifications are generated when an entity starts being tracked by the context or is marked as Deleted or Detached.

public class LocalView<TEntity> : ICollection<TEntity>, IEnumerable<TEntity>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging where TEntity : class
Public Class LocalView(Of TEntity As Class)
    Implements ICollection(Of TEntity), IEnumerable(Of TEntity), IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
Type Parameters
TEntity

The type of the entity in the local view.

Inheritance
System.ObjectSystem.Object
LocalView<TEntity>LocalView(Of TEntity)
Implements
System.Collections.Generic.ICollection<TEntity>System.Collections.Generic.ICollection(Of TEntity) System.Collections.Generic.IEnumerable<TEntity>System.Collections.Generic.IEnumerable(Of TEntity) System.Collections.IEnumerableSystem.Collections.IEnumerable

Inherited Members

System.Object

System.Object.ToString()System.Object.ToString()
System.Object.Equals(System.Object)System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()System.Object.GetHashCode()
System.Object.GetType()System.Object.GetType()
System.Object.MemberwiseClone()System.Object.MemberwiseClone()

Constructors

LocalView(DbSet) LocalView(DbSet(Of TEntity))

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

public LocalView(DbSet<TEntity> set)
Public Sub New(set As DbSet(Of TEntity))
Parameters
set
DbSet<TEntity> DbSet(Of TEntity)

Properties

Count Count

The number of entities of type TEntity that are being tracked and are not marked as Deleted.

public virtual int Count { get; }
Public Overridable ReadOnly Property Count As Integer
Value
System.Int32 System.Int32

IsReadOnly IsReadOnly

False, since the collection is not read-only.

public virtual bool IsReadOnly { get; }
Public Overridable ReadOnly Property IsReadOnly As Boolean
Value
System.Boolean System.Boolean

Methods

Add(TEntity) Add(TEntity)

Adds a new entity to the DbContext. If the entity is not being tracked or is currently marked as deleted, then it becomes tracked as Added.

Note that only the given entity is tracked. Any related entities discoverable from the given entity are not automatically tracked.

public virtual void Add(TEntity item)
Public Overridable Sub Add(item As TEntity)
Parameters
item
TEntity TEntity

The item to start tracking.

Clear() Clear()

Marks all entities of type TEntity being tracked by the DbContext as Deleted.

Entities that are currently marked as Added will be marked as Detached since the Added state indicates that the entity has not been saved to the database and hence it does not make sense to attempt to delete it from the database.

public virtual void Clear()
Public Overridable Sub Clear

Contains(TEntity) Contains(TEntity)

Returns true if the entity is being tracked by the context and has not been marked as Deleted.

public virtual bool Contains(TEntity item)
Public Overridable Function Contains(item As TEntity) As Boolean
Parameters
item
TEntity TEntity

The entity to check.

Returns
System.Boolean System.Boolean

CopyTo(TEntity[], Int32) CopyTo(TEntity(), Int32)

Copies to an array all entities of type TEntity that are being tracked and are not marked as Deleted.

public virtual void CopyTo(TEntity[] array, int arrayIndex)
Public Overridable Sub CopyTo(array As TEntity(), arrayIndex As Integer)
Parameters
array
TEntity[] TEntity()

The array into which to copy entities.

arrayIndex
System.Int32 System.Int32

The index into the array to start copying.

GetEnumerator() GetEnumerator()

Returns an System.Collections.Generic.IEnumerator<T> for all tracked entities of type TEntity that are not marked as deleted.

public virtual IEnumerator<TEntity> GetEnumerator()
Public Overridable Function GetEnumerator As IEnumerator(Of TEntity)
Returns
System.Collections.Generic.IEnumerator<TEntity> System.Collections.Generic.IEnumerator(Of TEntity)

An enumerator for the collection.

OnCollectionChanged(NotifyCollectionChangedEventArgs) OnCollectionChanged(NotifyCollectionChangedEventArgs)

Raises the CollectionChanged event.

protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Protected Overridable Sub OnCollectionChanged(e As NotifyCollectionChangedEventArgs)
Parameters
e
NotifyCollectionChangedEventArgs NotifyCollectionChangedEventArgs

Details of the change.

OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs)

Raises the PropertyChanged event.

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
Protected Overridable Sub OnPropertyChanged(e As PropertyChangedEventArgs)
Parameters
e
PropertyChangedEventArgs PropertyChangedEventArgs

Details of the property that changed.

OnPropertyChanging(PropertyChangingEventArgs) OnPropertyChanging(PropertyChangingEventArgs)

Raises the PropertyChanging event.

protected virtual void OnPropertyChanging(PropertyChangingEventArgs e)
Protected Overridable Sub OnPropertyChanging(e As PropertyChangingEventArgs)
Parameters
e
PropertyChangingEventArgs PropertyChangingEventArgs

Details of the property that is changing.

Remove(TEntity) Remove(TEntity)

Marks the given entity as Deleted.

Entities that are currently marked as Added will be marked as Detached since the Added state indicates that the entity has not been saved to the database and hence it does not make sense to attempt to delete it from the database.

public virtual bool Remove(TEntity item)
Public Overridable Function Remove(item As TEntity) As Boolean
Parameters
item
TEntity TEntity

The entity to delete.

Returns
System.Boolean System.Boolean

True if the entity was being tracked and was not already Deleted.

ToBindingList() ToBindingList()

Returns an implementation that stays in sync with this collection.

public virtual BindingList<TEntity> ToBindingList()
Public Overridable Function ToBindingList As BindingList(Of TEntity)
Returns
BindingList<TEntity> BindingList(Of TEntity)

The binding list.

Events

CollectionChanged CollectionChanged

Occurs when the contents of the collection changes, either because an entity has been directly added or removed from the collection, or because an entity starts being tracked, or because an entity is marked as Deleted.

public virtual event NotifyCollectionChangedEventHandler CollectionChanged
Public Overridable Event CollectionChanged As NotifyCollectionChangedEventHandler

PropertyChanged PropertyChanged

Occurs when a property of this collection (such as Count) changes.

public virtual event PropertyChangedEventHandler PropertyChanged
Public Overridable Event PropertyChanged As PropertyChangedEventHandler

PropertyChanging PropertyChanging

Occurs when a property of this collection (such as Count) is changing.

public virtual event PropertyChangingEventHandler PropertyChanging
Public Overridable Event PropertyChanging As PropertyChangingEventHandler

Explicit Interface Implementations

IEnumerable.GetEnumerator() System.Collections.IEnumerable.GetEnumerator()

Returns an System.Collections.Generic.IEnumerator<T> for all tracked entities of type TEntity that are not marked as deleted.

IEnumerator IEnumerable.GetEnumerator()
Function System.Collections.IEnumerable.GetEnumerator As IEnumerator Implements IEnumerable.GetEnumerator
Returns
System.Collections.IEnumerator System.Collections.IEnumerator

An enumerator for the collection.