ComponentOne Data Source for Entity Framework
ComponentOne LiveLinq / How to Use LiveLinq / Query Collection / Using built-in IndexedCollection Class (LiveLinq to Objects)
In This Topic
    Using built-in IndexedCollection Class (LiveLinq to Objects)
    In This Topic

    Suppose first that we don't care what collection we use for our objects. We have a Customer class, something like


    Copy Code
    public class Customer
    {
        public string Name { get; set; }
        public string City { get; set; }
    }
    
       

    and we rely on LiveLinq to supply the collection class we need.

    Then we need look no further than the C1.LiveLinq.Collections.IndexedCollection class that is supplied by LiveLinq and is specifically optimized for LiveLinq use:


    Copy Code
    var customers = new IndexedCollection<Customer>();
    customers.Add(cust1);
    customers.Add(cust2);
    ...
    var query =
      from c in customers where c.City == "London" select c;
    
         

    Note that we can simply use customers instead of customers.AsIndexed(). It is because the IndexedCollection<T> class already implements the IIndexedSource<T> interface that LiveLinq needs, there is no need to use the AsIndexed() extension method to wrap it into that interface.

    There is an important consideration to be kept in mind using your own classes such as Customer above for collection elements. The Customer class above is so basic that it does not support property notifications. If you set one of its properties in code, nobody will notice it, including any indexes and live views|tag=How to create a live view you may create over that collection. Therefore it is highly necessary to provide property change notifications in such classes. Property change notifications is a standard .NET feature recommended for a variety of reasons, LiveLinq just adds another reason to do that. You can support property change notifications in your class by implementing the INotifyPropertyChanged interfaces. Or you can use LiveLinq for that, by deriving your class from IndexableObject Class and calling OnPropertyChanging/OnPropertyChanged like this:

    C#
    Copy Code
    public class Customer : IndexableObject
    {
        private string _name;
        public string Name
        {
            get {return _name} ;
            set
            {
                OnPropertyChanging("Name");
                _name = value;
                OnPropertyChanged("Name");
            }
        }
        private string _city;
        public string City
        {
            get {return _city};
            set
            {
                OnPropertyChanging("City");
                _city = value;
                OnPropertyChanged("City");
            }
        }
    }