Database ExtensionsTo Tracking CollectionTEntity Method
This converts an enumerable list of change tracking entities to an observable collection that will
notify the related data context of additions, changes, and deletions.
Definition
Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
A TrackingObservableCollectionT instance
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static TrackingObservableCollection<TEntity> ToTrackingCollection<TEntity>(
this IEnumerable<TEntity> entities,
DbContext dataContext
)
where TEntity : class, INotifyPropertyChanged
VB
<ExtensionAttribute>
Public Shared Function ToTrackingCollection(Of TEntity As {Class, INotifyPropertyChanged}) (
entities As IEnumerable(Of TEntity),
dataContext As DbContext
) As TrackingObservableCollection(Of TEntity)C++
public:
[ExtensionAttribute]
generic<typename TEntity>
where TEntity : ref class, INotifyPropertyChanged
static TrackingObservableCollection<TEntity>^ ToTrackingCollection(
IEnumerable<TEntity>^ entities,
DbContext^ dataContext
)F#
[<ExtensionAttribute>]
static member ToTrackingCollection :
entities : IEnumerable<'TEntity> *
dataContext : DbContext -> TrackingObservableCollection<'TEntity> when 'TEntity : not struct and INotifyPropertyChangedParameters
- entities IEnumerableTEntity
- An enumerable list of the entities
- dataContext DbContext
- The data context that is tracking the items
Type Parameters
- TEntity
- The entity type
Return Value
TrackingObservableCollectionTEntityA TrackingObservableCollectionT instance
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTEntity. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).Remarks
Example
C#
using var dataContext = new MyDbContext();
bsAccounts.DataSource = dc.LoadAll<Account>().ToTrackingCollection(dataContext);