DomainDataSource has two properties for getting the data out of it: Data and DataView. The Data property is what’s intended for exposure in Binding scenarios, for instance binding a DataGrid to the DomainDataSource. This property is typed very simply as an IEnumerable. The DataView property however is intended to be used for programmatic access to the entities exposed by the DomainDataSource. While the two properties currently return the same collection instance, this might not always be true, so it’s good to properly set the expectations of these two properties. If you need to work with the collection from the DomainDataSource, you should use the DataView property; but for Binding, you should use the Data property.
Awhile back, I asked for input on the DataView property and what API you would like to have for it. We were designing a new class that would be created expressly for the purpose of the DomainDataSource.DataView property. We wanted the API to do two thing for you: 1) Give you easy access to the properties and methods you will frequently use on the collection; and 2) Hide the properties and methods that are required to be implemented for interfaces but that you would not need to access programmatically often. The result of this effort was a class named DomainDataSourceView. You will see this with the PDC release of RIA Services.
Frequently Used Members
The following members are exposed as public properties and methods on the DomainDataSourceView class (DomainDataSource.DataView property):
- General Collection Members
- int Count
- object CurrentItem
- int CurrentPosition
- bool IsEmpty
- int TotalItemCount
- object this[int index]
- EventHandler CurrentChanged
- CurrentChangingEventHandler CurrentChanging
- bool Contains(object item)
- object GetItemAt(int index)
- int IndexOf(object item)
- bool MoveCurrentTo(object item)
- bool MoveCurrentToFirst()
- bool MoveCurrentToLast()
- bool MoveCurrentToNext()
- bool MoveCurrentToPosition(int position)
- bool MoveCurrentToPrevious()
- Collection Editing Members
- bool CanAdd
- bool CanRemove
- void Add(object item)
- void Remove(object item)
- void RemoteAt(int index)
- Paging Members
- bool CanChangePage
- int PageCount
- int PageIndex
- int PageSize
- EventHandler<EventArgs> PageChanged
- EventHandler<PageChangingEventArgs> PageChanging
- bool MoveToFirstPage()
- bool MoveToLastPage()
- bool MoveToNextPage()
- bool MoveToPage(int pageIndex)
- bool MoveToPreviousPage()
Interface Implementations
The following members are implemented on the DomainDataSourceView class, but they are explicitly implemented against the interfaces. This means that you won’t get intellisense for the members, and you can’t use them directly, but if you (or Silverlight/SDK controls) cast an DomainDataSourceView instance to the interface, you can access the members. This is done for members we don’t expect you to need frequently yourself, but they are needed for the interfaces.
- ICollectionView
- bool CanFilter
- This property will always return false since DomainDataSource doesn’t use Predicate-based filtering.
- bool CanGroup
- bool CanSort
- CultureInfo Culture
- Predicate<object> Filter
- This property will throw an exception, as CanFilter is always false since DomainDataSource doesn’t use Predicate-based filtering.
- ObservableCollection<GroupDescription> GroupDescriptions
- ReadOnlyObservableCollection<object> Groups
- bool IsCurrentAfterLast
- bool IsCurrentBeforeFirst
- SortDescriptionCollection SortDescriptions
- IEnumerable SourceCollection
- EventHandler CurrentChanged
- CurrentChangingEventHandler CurrentChanging
- IDisposable DeferRefresh()
- void Refresh()
- bool CanFilter
- IEnumerable
- IEnumerator GetEnumerator()
- INotifyCollectionChanged
- NotifyCollectionChangedEventHandler CollectionChanged
- IEditableCollectionView
- bool CanAddNew
- bool CanCancelEdit
- object CurrentAddItem
- object CurrentEditItem
- bool IsAddingNew
- bool IsEditingItem
- NewItemPlaceholderPosition NewItemPlaceholderPosition
- object AddNew()
- void CancelEdit()
- void CancelNew()
- void CommitEdit()
- void CommitNew()
- void EditItem(object item)
- INotifyCollectionChanged
- PropertyChangedEventHandler PropertyChanged
- Only raises events for public properties, and not those are are only explicitly implemented on the interfaces
- PropertyChangedEventHandler PropertyChanged
I do hope that this API provides the members you’ll need to access directly, while keeping the API as trim as possible too.