我在Devexpress中用Scaffolding wizard創建了一個WPF MVVM項目,創建的所有東西都正常工作,我甚至修改了網格,因此他們調用RowUpdated
上的SaveCommand
。以編程方式在MVVM Devexpress項目中保存數據
現在我試圖以編程方式插入新的寄存器,我的策略是從我的模型中獲取CollectionViewModel
的實例,並使用它的Save
方法將相同模型中的對象作爲參數發送。
我正在閱讀this指南,但仍然無法找到我做錯了什麼。
這是代碼
Transaction transaction = new Transaction();
transaction.IdClient = 1;
TransactionCollectionViewModel tcvm = TransactionCollectionViewModel.Create(UnitOfWorkSource.GetUnitOfWorkFactory());
tcvm.Save(transaction);
並調用Save
功能
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=DevExpress.Mvvm.v16.1.DataModel
StackTrace:
at DevExpress.Mvvm.DataModel.RepositoryExtensions.<>c__DisplayClass1_0`3.<GetProjectionPrimaryKey>b__0(TEntity x)
at DevExpress.Mvvm.DataModel.RepositoryExtensions.GetProjectionValue[TEntity,TProjection,TEntityResult,TProjectionResult](TProjection value, Func`2 entityFunc, Func`2 projectionFunc)
at DevExpress.Mvvm.DataModel.RepositoryExtensions.GetProjectionPrimaryKey[TEntity,TProjection,TPrimaryKey](IRepository`2 repository, TProjection projectionEntity)
at DevExpress.Mvvm.DataModel.RepositoryExtensions.FindExistingOrAddNewEntity[TEntity,TProjection,TPrimaryKey](IRepository`2 repository, TProjection projectionEntity, Action`2 applyProjectionPropertiesToEntity)
at DevExpress.Mvvm.ViewModel.CollectionViewModelBase`4.Save(TProjection projectionEntity)
at Template.ViewModels.ClientCollectionViewModel..ctor(IUnitOfWorkFactory`1 unitOfWorkFactory) in C:\Users\edwin\Source\Workspaces\INVASST\Template\Template\ViewModels\Client\ClientCollectionViewModel.cs:line 37
at ClientCollectionViewModel_97cd3897_6fb7_469b_9928_d61260161e61..ctor(IUnitOfWorkFactory`1 unitOfWorkFactory)
InnerException:
我使用的DevExpress 16.1.5時,它給了我這個錯誤的變量tcvm
和項目使用HybridApp模板