src/Shared/EntityFramework/Core/Objects/DataClasses/EntityCollection.cs
/// <summary>Removes all entities from the collection. </summary>
Removes all entities from the collection.
Removes all entities from the collection .
public void Clear()
        {
            DeferredLoad();
            if (WrappedOwner.Entity != null)
            {
                var shouldFireEvent = (CountInternal > 0);
                if (null != _wrappedRelatedEntities)
                {
                    var affectedEntities = new List<IEntityWrapper>(_wrappedRelatedEntities.Values);
                    try
                    {
                        _suppressEvents = true;
                        foreach (var wrappedEntity in affectedEntities)
                        {
                            Remove(wrappedEntity, false);
                            if (UsingNoTracking)
                            {
                                var relatedEnd = GetOtherEndOfRelationship(wrappedEntity);
                                relatedEnd.OnRelatedEndClear();
                            }
                        }
                        Debug.Assert(_wrappedRelatedEntities.Count == 0);
                    }
                    finally
                    {
                        _suppressEvents = false;
                    }
                    if (UsingNoTracking)
                    {
                        _isLoaded = false;
                    }
                }
                if (shouldFireEvent)
                {
                    OnAssociationChanged(CollectionChangeAction.Refresh, null);
                }
            }
            else
            {
                if (_wrappedRelatedEntities != null)
                {
                    _wrappedRelatedEntities.Clear();
                }
            }
        }
public void Clear ( ) { DeferredLoad ( ) ; if ( WrappedOwner . Entity != null ) { var shouldFireEvent = ( CountInternal > 0 ) ; if ( null != _wrappedRelatedEntities ) { var affectedEntities = new List < IEntityWrapper > ( _wrappedRelatedEntities . Values ) ; try { _suppressEvents = true ; foreach ( var wrappedEntity in affectedEntities ) { Remove ( wrappedEntity , false ) ; if ( UsingNoTracking ) { var relatedEnd = GetOtherEndOfRelationship ( wrappedEntity ) ; relatedEnd . OnRelatedEndClear ( ) ; } } Debug . Assert ( _wrappedRelatedEntities . Count == 0 ) ; } finally { _suppressEvents = false ; } if ( UsingNoTracking ) { _isLoaded = false ; } } if ( shouldFireEvent ) { OnAssociationChanged ( CollectionChangeAction . Refresh , null ) ; } } else { if ( _wrappedRelatedEntities != null ) { _wrappedRelatedEntities . Clear ( ) ; } } }
Removes all entities from the collection.
Removes all entities from the collection .
// Remove Entity // The other end of relationship can be the EntityReference or EntityCollection // If the other end is EntityReference, its IsLoaded property should be set to FALSE // Disconnected Clear should be dispatched to the internal collection