how to change loadoperation.entities?
-
Friday, April 27, 2012 11:54 AM

when i use domainservice's load method to load a query, as it retured the loadoperation.entities collection is readonly
and I can't change it. what i want to do is fetching entitiesfrom domainservice and bind it to a gridview. i want to remove an entity from gridview and change database. here is my code snipper.
I met two problems:
1: visual studio prompt me that the loadoperation.entities collection is readonly and can't change
2: commandparameter not be passed to viewmodel
Follow is my code snipper:
[view.xaml markup]
<StackPanel > <telerik:RadButton Content="Add" Height="Auto" Name="btnAdd" VerticalAlignment="Top"Command="{Binding AddCommand}" /> <telerik:RadButton Content="Edit" Height="Auto" Name="btnEdit" Command="{Binding EditCommand}" CommandParameter="{Binding ElementName=departmentGridView,Path=SelectedItem}" /> <telerik:RadButton Content="Delete" Name="btnDelete" Command="{Binding DeleteCommand}" CommandParameter="{Binding ElementName=departmentGridView,Path=SelectedItem}" /> </StackPanel> <telerik:RadGridView HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGroupPanel="False" ShowColumnHeaders="True" RowIndicatorVisibility="Collapsed" ItemsSource="{Binding DepartmentTypeList}" Name="departmentTypeGridView" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" AutoGenerateColumns="False" Grid.RowSpan="1" Grid.Row="1"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Name" Width="*" DataMemberBinding="{Binding Name}" IsSortable="False" /> </telerik:RadGridView.Columns> </telerik:RadGridView>[viewmodel code]
private readonly DepartmentTypeContext _DomainContext; public DepartmentTypeViewModel() { this._DomainContext = new DepartmentTypeContext(); this._DeleteCommand = new DelegateCommand(this.Delete,()=>_DepartmentTypeList!=null && _DepartmentTypeList.CurrentItem!=null?true:false); LoadDepartmentType(); } void _DepartmentTypeList_CurrentChanged(object sender, System.EventArgs e) { (_DeleteCommand as DelegateCommand).RaiseCanExecuteChanged(); } private void LoadDepartmentType() { _DomainContext.Load<DepartmentType>(_DomainContext.GetDepartmentTypeQuery(),this.LoadCallBack,null); } private void LoadCallBack(LoadOperation<DepartmentType> lo) { if (lo.HasError) { MessageBox.Show(lo.Error.Message); return; } CollectionViewSource dataSource = new CollectionViewSource(); dataSource.Source = lo.AllEntities; DepartmentTypeList = dataSource.View; DepartmentTypeList.MoveCurrentToFirst(); DepartmentTypeList.CurrentChanged += new System.EventHandler(_DepartmentTypeList_CurrentChanged); } private ICollectionView _DepartmentTypeList; public ICollectionView DepartmentTypeList { get { return _DepartmentTypeList; } private set { if (_DepartmentTypeList != value) { _DepartmentTypeList = value; RaisePropertyChanged(() => this.DepartmentTypeList); } } } private ICommand _AddCommand; public ICommand AddCommand { get { return _AddCommand; } set { if (_AddCommand != value) { this._AddCommand = value; RaisePropertyChanged(() => this._AddCommand); } } } private ICommand _EditCommand; public ICommand EditCommand { get { return _EditCommand; } set { if (_EditCommand != value) { this._EditCommand = value; RaisePropertyChanged(() => this._EditCommand); } } } private ICommand _DeleteCommand; public ICommand DeleteCommand { get { return _DeleteCommand; } set { if (_DeleteCommand != value) { _DeleteCommand = value; RaisePropertyChanged(() => this._DeleteCommand); } } } private void Delete() { if (DepartmentTypeList.CurrentItem != null) { IList list = DepartmentTypeList.SourceCollection as IList; list.Remove(DepartmentTypeList.CurrentItem); } }
All Replies
-
Friday, April 27, 2012 1:07 PM
weakinverse
With single block
LoadOperation<DepartmentType> lo = _DomainContext.Load(DomainContext.GetDepartmentTypeQuery())
lo.Completed += (s, e) =>
{
this._DepartmentTypeList = new CollectionView(this._DomainContext.DepartmentType);
this.RaisePropertyChanged(() => this.DepartmentType);
};
-
Friday, April 27, 2012 2:29 PM
You might find that the EntityList gives you better results. You will find a full list of options at http://blogs.msdn.com/b/kylemc/archive/2010/12/02/collection-binding-options-in-wcf-ria-services-sp1.aspx
-
Friday, April 27, 2012 7:37 PM
thanks for your help

