语言

LocalView<TEntity> 类

定义

一个集合,该集合与给定类型的实体保持同步,由 a DbContext. 调用 Local 以获取本地视图。

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
[System.Runtime.CompilerServices.Nullable(0)]
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
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
[<System.Runtime.CompilerServices.Nullable(0)>]
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
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

类型参数

TEntity

本地视图中实体的类型。

继承
LocalView<TEntity>
特性
实现

注解

此本地视图将在从上下文中添加或删除实体时保持同步。 同样,从本地视图中添加或删除的实体将自动添加到上下文中或从上下文中删除。

将实体添加到此集合将导致该实体在上下文的状态中 Added 被跟踪,除非它已被跟踪。

从此集合中删除实体将导致该实体被标记为 Deleted“已添加”,除非它以前处于“已添加”状态,在这种情况下,该实体将从上下文中分离。

集合实现INotifyCollectionChanged,INotifyPropertyChangingINotifyPropertyChanging并在上下文开始跟踪实体或标记为Deleted或标记为或Detached标记时生成通知。

请勿直接将此类型用于数据绑定。 而是调用ToObservableCollection()WPF绑定或 ToBindingList() WinForms。

有关详细信息和示例,请参阅 EF Core 中跟踪实体的本地视图 。

构造函数

名称 说明
LocalView<TEntity>(DbSet<TEntity>)

这是一个内部 API,支持Entity Framework Core基础结构,不受与公共 API 相同的兼容性标准的约束。 可以在任何版本中更改或删除它,而不通知。 只需在代码中直接使用它,并非常谨慎地知道这样做可能会导致应用程序在更新到新的Entity Framework Core版本时失败。

属性

名称 说明
Count

正在跟踪且未标记为 Deleted 的类型的 TEntity 实体数。

IsReadOnly

False,因为集合不是只读的。

方法

名称 说明
Add(TEntity)

将新实体添加到 .DbContext 如果实体未被跟踪或当前标记为已删除,则它将被跟踪为 Added。

Clear()

将类型的所有实体 TEntityDbContextDeleted标记为 ..

Contains(TEntity)

返回 true 上下文正在跟踪实体,并且尚未标记为“已删除”。

CopyTo(TEntity[], Int32)

复制到要跟踪且未标记为“已删除”的所有类型的 TEntity 实体的数组。

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

返回由上下文跟踪的第一个实体的一个 EntityEntry<TEntity> 实体,其中给定属性的值与给定的值匹配。 该条目提供对实体的更改跟踪信息和操作的访问权限。

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

返回由上下文跟踪的第一个实体的一个 EntityEntry<TEntity> 实体,其中给定属性的值与给定的值匹配。 该条目提供对实体的更改跟踪信息和操作的访问权限。

FindEntry<TKey>(TKey)

在 EntityEntry<TEntity> 更改跟踪器中查找具有给定主键值的实体(如果跟踪它)。 null 如果未跟踪具有给定键值的实体,则返回 。 此方法从不查询数据库。

FindEntry<TProperty>(IProperty, TProperty)

返回由给定属性的值与给定值匹配的上下文跟踪的第一个实体的一个 EntityEntry<TEntity> 实体。 该条目提供对实体的更改跟踪信息和操作的访问权限。

FindEntry<TProperty>(String, TProperty)

返回由给定属性的值与给定值匹配的上下文跟踪的第一个实体的一个 EntityEntry<TEntity> 实体。 该条目提供对实体的更改跟踪信息和操作的访问权限。

FindEntryUntyped(IEnumerable<Object>)

查找 EntityEntry<TEntity> 在更改跟踪器中具有给定主键值的实体(如果跟踪它)。 null 如果未跟踪具有给定键值的实体,则返回该实体。 此方法从不查询数据库。

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

返回由上下文跟踪的每个实体的一个 EntityEntry 值,其中给定属性的值与给定的值匹配。 这些条目提供对每个实体的更改跟踪信息和操作的访问权限。

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

返回由上下文跟踪的每个实体的一个 EntityEntry 值,其中给定属性的值与给定的值匹配。 这些条目提供对每个实体的更改跟踪信息和操作的访问权限。

GetEntries<TProperty>(IProperty, TProperty)

返回由上下文跟踪的每个实体的一个 EntityEntry<TEntity> 值,其中给定属性的值与给定值匹配。 这些条目提供对每个实体的更改跟踪信息和操作的访问权限。

GetEntries<TProperty>(String, TProperty)

返回由上下文跟踪的每个实体的一个 EntityEntry<TEntity> 值,其中给定属性的值与给定值匹配。 这些条目提供对每个实体的更改跟踪信息和操作的访问权限。

GetEnumerator()

返回未标记为已删除的类型TEntity的所有跟踪实体的一个IEnumerator<T>。

OnCollectionChanged(NotifyCollectionChangedEventArgs)

引发 CollectionChanged 事件。

OnPropertyChanged(PropertyChangedEventArgs)

引发 PropertyChanged 事件。

OnPropertyChanging(PropertyChangingEventArgs)

引发 PropertyChanging 事件。

Remove(TEntity)

将给定实体标记为 Deleted.

Reset()

重置此视图,清除使用和创建的任何IBindingList创建ToObservableCollection()项,并清除注册PropertyChanged的任何事件,PropertyChanging或CollectionChanged。ObservableCollection<T>ToBindingList()

ToBindingList()

返回一个 BindingList<T> 实现,该实现与此集合保持同步。 将此用于 WinForms 数据绑定。

ToObservableCollection()

返回一个 ObservableCollection<T> 实现,该实现与此集合保持同步。 将此用于WPF数据绑定。

事件

名称 说明
CollectionChanged

当集合的内容发生更改时发生,要么是因为已从集合中直接添加或删除实体,要么因为实体开始被跟踪,或者因为实体被标记为“已删除”。

PropertyChanged

当此集合的属性(如 Count)发生更改时发生。

PropertyChanging

当此集合的属性(如 Count)发生更改时发生。

显式接口实现

名称 说明
IEnumerable.GetEnumerator()

返回未标记为已删除的类型TEntity的所有跟踪实体的一个IEnumerator<T>。

IListSource.ContainsListCollection

获取一个值,该值指示集合是否是 System.Collections.IList 对象的集合。 始终返回 false。

IListSource.GetList()

尝试将数据直接绑定到 a1 LocalView<TEntity>时,数据绑定框架调用此方法。

适用于