예제 #1
0
        /// <summary>Loads the collection from another collection.</summary>
        /// <param name="items">Collection whose elements will be loaded into the DataServiceCollection.</param>
        /// <remarks>
        /// When tracking is enabled, the behavior of Load would be to attach all those entities that are not already tracked by the context
        /// associated with the collection. The operation will go deep into the input entities so that all related
        /// entities are attached to the context if not already present. All entities in <paramref name="items"/>
        /// will be tracked after Load is done.
        /// Load method checks for duplication. The collection will ignore any duplicated items been loaded.
        /// For large amount of items, consider DataServiceContext.LoadProperty instead.
        /// </remarks>
        public void Load(IEnumerable <T> items)
        {
            DataServiceCollection <T> .ValidateIteratorParameter(items);

            if (this.trackingOnLoad)
            {
                // This throws if no context can be obtained, no need to check here
                DataServiceContext context = DataServiceCollection <T> .GetContextFromItems(items);

                this.trackingOnLoad = false;

                this.StartTracking(context, items, this.entitySetName, this.entityChangedCallback, this.collectionChangedCallback);
            }
            else
            {
                this.StartLoading();
                try
                {
                    this.InternalLoadCollection(items);
                }
                finally
                {
                    this.FinishLoading();
                }
            }
        }
예제 #2
0
 public DataServiceCollection(DataServiceContext context, IEnumerable <T> items, TrackingMode trackingMode, string entitySetName, Func <EntityChangedParams, bool> entityChangedCallback, Func <EntityCollectionChangedParams, bool> collectionChangedCallback)
 {
     if (trackingMode == TrackingMode.AutoChangeTracking)
     {
         if (context == null)
         {
             if (items == null)
             {
                 this.trackingOnLoad            = true;
                 this.entitySetName             = entitySetName;
                 this.entityChangedCallback     = entityChangedCallback;
                 this.collectionChangedCallback = collectionChangedCallback;
             }
             else
             {
                 context = DataServiceCollection <T> .GetContextFromItems(items);
             }
         }
         if (!this.trackingOnLoad)
         {
             if (items != null)
             {
                 DataServiceCollection <T> .ValidateIteratorParameter(items);
             }
             this.StartTracking(context, items, entitySetName, entityChangedCallback, collectionChangedCallback);
         }
     }
     else if (items != null)
     {
         this.Load(items);
     }
 }
예제 #3
0
        /// <summary>Creates a new DataServiceCollection.</summary>
        /// <param name="context"><see cref="DataServiceContext"/> associated with the new collection.</param>
        /// <param name="items">Enumeration of items to initialize the new DataServiceCollection with.</param>
        /// <param name="trackingMode">The tracking mode for the new collection.</param>
        /// <param name="entitySetName">The name of the entity set the elements in the collection belong to.</param>
        /// <param name="entityChangedCallback">Delegate that gets called when an entity changes.</param>
        /// <param name="collectionChangedCallback">Delegate that gets called when an entity collection changes.</param>
        public DataServiceCollection(
            DataServiceContext context,
            IEnumerable <T> items,
            TrackingMode trackingMode,
            string entitySetName,
            Func <EntityChangedParams, bool> entityChangedCallback,
            Func <EntityCollectionChangedParams, bool> collectionChangedCallback)
        {
            if (trackingMode == TrackingMode.AutoChangeTracking)
            {
                if (context == null)
                {
                    if (items == null)
                    {
                        // Enable tracking on first Load/LoadAsync call, when we can obtain a context
                        this.trackingOnLoad = true;

                        // Save off these for when we enable tracking later
                        this.entitySetName             = entitySetName;
                        this.entityChangedCallback     = entityChangedCallback;
                        this.collectionChangedCallback = collectionChangedCallback;
                    }
                    else
                    {
                        // This throws if no context can be obtained, no need to check here
                        context = DataServiceCollection <T> .GetContextFromItems(items);
                    }
                }

                if (!this.trackingOnLoad)
                {
                    if (items != null)
                    {
                        DataServiceCollection <T> .ValidateIteratorParameter(items);
                    }

                    this.StartTracking(context, items, entitySetName, entityChangedCallback, collectionChangedCallback);
                }
            }
            else if (items != null)
            {
                this.Load(items);
            }
        }