語言

LocalView<TEntity> 類別

定義

一個與被追蹤 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作了 、 INotifyPropertyChanging、 , INotifyPropertyChanging 使得當實體開始被上下文追蹤或標記為 Deleted 或 Detached時,會產生通知。

請勿直接使用此類型進行資料綁定。 請使用ToObservableCollection()WPF綁定或ToBindingList()WinForms。

更多資訊與範例請參閱 EF Core中追蹤實體的本地視圖 。

建構函式

名稱 Description
LocalView<TEntity>(DbSet<TEntity>)

這是一個內部 API,支援 Entity Framework Core 基礎架構,且不受公開 API 相同的相容性標準約束。 該內容可能會在任何新聞稿中未經通知而更改或移除。 你應該只在程式碼中直接使用它,並且要非常謹慎,並且要知道這樣做可能會導致更新到新的 Entity Framework Core 版本時應用程式失敗。

屬性

名稱 Description
Count

正在追蹤且未被標記為刪除的類型實體 TEntity 數量。

IsReadOnly

錯誤,因為該集合並非唯讀。

方法

名稱 Description
Add(TEntity)

為 新增一個實體。DbContext 如果該實體未被追蹤或目前標記為刪除,則該實體會被追蹤為 Added。

Clear()

標記所有類型的實體 TEntity 被 DbContext 追蹤為 Deleted。

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)

對於第一個被上下文追蹤的實體,當該屬性的值與給定值相符時,回傳 a EntityEntry<TEntity> 。 該條目提供實體變更追蹤資訊及操作權限。

FindEntry<TProperty>(String, TProperty)

對於第一個被上下文追蹤的實體,當該屬性的值與給定值相符時,回傳 a 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()

回傳 IEnumerator<T> 所有未標記為已刪除的追蹤 TEntity 實體。

OnCollectionChanged(NotifyCollectionChangedEventArgs)

引發 CollectionChanged 事件。

OnPropertyChanged(PropertyChangedEventArgs)

引發 PropertyChanged 事件。

OnPropertyChanging(PropertyChangingEventArgs)

引發 PropertyChanging 事件。

Remove(TEntity)

標記給定實體為 Deleted。

Reset()

重置此視圖,清除 IBindingList 所有以 和 ToBindingList()ObservableCollection<T> 創建的 ToObservableCollection(),並清除在 PropertyChanged、 PropertyChanging或 CollectionChanged上註冊的事件。

ToBindingList()

回傳 BindingList<T> 一個與此集合同步的實作。 用這個來做 WinForms 資料綁定。

ToObservableCollection()

回傳 ObservableCollection<T> 一個與此集合同步的實作。 用這個來綁定 WPF 資料。

事件

名稱 Description
CollectionChanged

當集合內容發生變化,可能是因為某實體被直接新增或移除,或是某實體開始被追蹤,或是某實體被標記為已刪除。

PropertyChanged

當該集合的某個屬性(例如 Count)發生變化時。

PropertyChanging

當該集合的某個性質(例如 Count)發生變化時。

明確介面實作

名稱 Description
IEnumerable.GetEnumerator()

回傳 IEnumerator<T> 所有未標記為已刪除的追蹤 TEntity 實體。

IListSource.ContainsListCollection

會取得一個值,表示該集合是否為 System.Collections.IList 物件的集合。 一律傳回 false。

IListSource.GetList()

當資料綁定框架嘗試直接 LocalView<TEntity>對資料綁定時,會呼叫此方法。

適用於