views:

29

answers:

1

I created a wcf ria service application (with Silverlight 4 and SQL Server 2008 Express).

Within my domain model I have two tables projects and times which are linked by a foreign key. This works all very well, as long as I use the domain context methods directly to add, update, delete objects to the underlying database.

Now I wanted to change to a PagedCollectionView to get support for pagin, sorting, filtering and - especially important - for transaction support (EditItem, CommitEdit, CancelEdit etc.).

My problem is that the AddNew method of the PagedCollectionView always results in an exception "InvalidOperationException AddNew is not allowed for this view." All other methods like EditItem, Commit, Cancel are working without any problems.

I searched for hours now in the web, but couldn't find an explanation for this problem and hope you can help me.

Here's some code from my app:

definition of lists in viewModel:

    [Export(typeof(TimeTFTViewListViewModel))] 
    public class TimeTFTViewListViewModel : MEViewModelBase//, IPartImportsSatisfiedNotification 
    { 
            private ITimeModel _model; 

            private IEnumerable<TimeObject> _timeList; 
            public IEnumerable<TimeObject> TimeList 
            { 
                    get { return _timeList; } 
                    private set 
                    { 
                            if (value != _timeList) 
                            { 
                                    _timeList = value; 
                                    RaisePropertyChanged("TimeList"); 
                            } 
                    } 
            } 
            private PagedCollectionView _timePagedList; 
            public PagedCollectionView TimePagedList 
            { 
                    get { return _timePagedList; } 
                    private set 
                    { 
                            if (value != _timePagedList) 
                            { 
                                    _timePagedList = value; 
                                    RaisePropertyChanged("TimePagedList"); 
                            } 
                    } 
            }

loading of the data:

            [ImportingConstructor] 
            public TimeTFTViewListViewModel(ITimeModel timeModel) 
            { 
                    _model = timeModel; 
                    _model.GetTimesComplete += new EventHandler<EntityResultsArgs<TimeObject>>(_model_GetTimesComplete); 

                    CreateCommands(); 
                    CreateMessages(); 
            } 

            void _model_GetTimesComplete(object sender, EntityResultsArgs<TimeObject> e) 
            { 
                    if (e.Error != null) 
                    { 
                            ErrorMessage = e.Error.Message; 
                    } 
                    else 
                    { 
                            TimeList = e.Results; 
                            TimePagedList = new PagedCollectionView(TimeList); 
                            TimePagedList.CurrentChanged += new EventHandler(TimeList_CurrentChanged); 
                    } 
            }

Add a new item:

            public void AddTime() 
            { 
                    _timePagedList.AddNew(); 

                    _timePagedList.MoveCurrentTo(newTime);  
                    AppMessages.ChangeViewMessage.Send(new ChangeViewMsg() { ModulType = ModuleTypeEnum.TimeTFT, ViewType = ViewTypeEnum.Detail }); 
            }

The exception is appearing on the line _timePagedList.AddNew();

I hope someone can bring in some light.

Thanks Dirk