LocalView<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.

public class LocalView<TEntity> : System.Collections.Generic.ICollection<TEntity>, System.Collections.Generic.IEnumerable<TEntity>, System.Collections.Specialized.INotifyCollectionChanged, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.INotifyPropertyChanging where TEntity : class
public class LocalView<TEntity> : System.Collections.Generic.ICollection<TEntity>, System.Collections.Generic.IEnumerable<TEntity>, System.Collections.Specialized.INotifyCollectionChanged, System.ComponentModel.IListSource, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.INotifyPropertyChanging where TEntity : class
type LocalView<'Entity (requires 'Entity : null)> = class
    interface ICollection<'Entity (requires 'Entity : null)>
    interface seq<'Entity (requires 'Entity : null)>
    interface IEnumerable
    interface INotifyCollectionChanged
    interface INotifyPropertyChanged
    interface INotifyPropertyChanging
type LocalView<'Entity (requires 'Entity : null)> = class
    interface ICollection<'Entity (requires 'Entity : null)>
    interface seq<'Entity (requires 'Entity : null)>
    interface IEnumerable
    interface INotifyCollectionChanged
    interface INotifyPropertyChanged
    interface INotifyPropertyChanging
    interface IListSource
Public Class LocalView(Of TEntity)
Implements ICollection(Of TEntity), IEnumerable(Of TEntity), INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
Public Class LocalView(Of TEntity)
Implements ICollection(Of TEntity), IEnumerable(Of TEntity), IListSource, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging

Type Parameters

TEntity

The type of the entity in the local view.

Inheritance
LocalView<TEntity>
Implements

Remarks

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 INotifyCollectionChanged, INotifyPropertyChanging, and INotifyPropertyChanging such that notifications are generated when an entity starts being tracked by the context or is marked as Deleted or Detached.

Do not use this type directly for data binding. Instead call ToObservableCollection() for WPF binding, or ToBindingList() for WinForms.

See Local views of tracked entities in EF Core for more information and examples.

Constructors

LocalView<TEntity>(DbSet<TEntity>)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

Properties

Count

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

IsReadOnly

False, since the collection is not read-only.

Methods

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.

Clear()

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

Contains(TEntity)

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

CopyTo(TEntity[], Int32)

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

FindEntry(IEnumerable<IProperty>, IEnumerable<Object>)

Returns an EntityEntry<TEntity> for the first entity being tracked by the context where the value of the given property matches the given values. The entry provide access to change tracking information and operations for the entity.

FindEntry(IEnumerable<String>, IEnumerable<Object>)

Returns an EntityEntry<TEntity> for the first entity being tracked by the context where the value of the given property matches the given values. The entry provide access to change tracking information and operations for the entity.

FindEntry<TKey>(TKey)

Finds an EntityEntry<TEntity> for the entity with the given primary key value in the change tracker, if it is being tracked. null is returned if no entity with the given key value is being tracked. This method never queries the database.

FindEntry<TProperty>(IProperty, TProperty)

Returns an EntityEntry<TEntity> for the first entity being tracked by the context where the value of the given property matches the given value. The entry provide access to change tracking information and operations for the entity.

FindEntry<TProperty>(String, TProperty)

Returns an EntityEntry<TEntity> for the first entity being tracked by the context where the value of the given property matches the given value. The entry provide access to change tracking information and operations for the entity.

FindEntryUntyped(IEnumerable<Object>)

Finds an EntityEntry<TEntity> for the entity with the given primary key values in the change tracker, if it is being tracked. null is returned if no entity with the given key values is being tracked. This method never queries the database.

GetEntries(IEnumerable<IProperty>, IEnumerable<Object>)

Returns an EntityEntry for each entity being tracked by the context where the values of the given properties matches the given values. The entries provide access to change tracking information and operations for each entity.

GetEntries(IEnumerable<String>, IEnumerable<Object>)

Returns an EntityEntry for each entity being tracked by the context where the values of the given properties matches the given values. The entries provide access to change tracking information and operations for each entity.

GetEntries<TProperty>(IProperty, TProperty)

Returns an EntityEntry<TEntity> for each entity being tracked by the context where the value of the given property matches the given value. The entries provide access to change tracking information and operations for each entity.

GetEntries<TProperty>(String, TProperty)

Returns an EntityEntry<TEntity> for each entity being tracked by the context where the value of the given property matches the given value. The entries provide access to change tracking information and operations for each entity.

GetEnumerator()

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

OnCollectionChanged(NotifyCollectionChangedEventArgs)

Raises the CollectionChanged event.

OnPropertyChanged(PropertyChangedEventArgs)

Raises the PropertyChanged event.

OnPropertyChanging(PropertyChangingEventArgs)

Raises the PropertyChanging event.

Remove(TEntity)

Marks the given entity as Deleted.

Reset()

Resets this view, clearing any IBindingList created with ToBindingList() and any ObservableCollection<T> created with ToObservableCollection(), and clearing any events registered on PropertyChanged, PropertyChanging, or CollectionChanged.

ToBindingList()

Returns a BindingList<T> implementation that stays in sync with this collection. Use this for WinForms data binding.

ToObservableCollection()

Returns an ObservableCollection<T> implementation that stays in sync with this collection. Use this for WPF data binding.

Events

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.

PropertyChanged

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

PropertyChanging

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

Explicit Interface Implementations

IEnumerable.GetEnumerator()

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

IListSource.ContainsListCollection

Gets a value indicating whether the collection is a collection of System.Collections.IList objects. Always returns false.

IListSource.GetList()

This method is called by data binding frameworks when attempting to data bind directly to a LocalView<TEntity>.

Applies to