public virtual void Reset(IEnumerable <T> collection)
    {
        if (collection.IsNullOrEmpty() && this.Items.IsNullOrEmpty())
        {
            return;
        }
        // Step 0: Check if collection is exactly same as this.Items
        if (IEnumerableUtils.Equals <T>(collection, this.Items))
        {
            return;
        }
        int count = this.Count;

        // Step 1: Clear the old items
        this.Items.Clear();
        // Step 2: Add new items
        if (!collection.IsNullOrEmpty())
        {
            foreach (T item in collection)
            {
                this.Items.Add(item);
            }
        }
        // Step 3: Don't forget the event
        if (this.Count != count)
        {
            this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
        }
        this.OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
        this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
    }
Exemplo n.º 2
0
        /// <summary>
        /// The column which provides row numbers for this table
        /// </summary>
        ICompositeKey BuildPrimaryKey()
        {
            if (ParentStatement.SelectColumns == null)
            {
                throw new InvalidOperationException("Column accessed before ParentStatment initialized.");
            }

            var pks = IEnumerableUtils.Create(
                Math.Max(1, ExplicitPrimaryKeys),
                GetPk);

            return(new CompositeKey(pks));

            ISelectColumn GetPk(int index)
            {
                var alias = Alias == SqlStatementConstants.RootObjectAlias
                    ? SqlStatementConstants.PrimaryKeyName + index
                    : $"{Alias}.{SqlStatementConstants.PrimaryKeyName}{index}";

                return(ParentStatement.SelectColumns[alias]);
            }
        }