c# - Save data programmatically in a MVVM Devexpress project -


i created wpf mvvm project in devexpress scaffolding wizard , created works fine, modified grids call savecommand on rowupdated.

now i'm trying insert new registers programmatically , strategy , instance of collectionviewmodel model , use save method sending object same model parameter.

i reading this guide still couldn't find i'm doing wrong.

this code

        transaction transaction = new transaction();         transaction.idclient = 1;          transactioncollectionviewmodel tcvm = transactioncollectionviewmodel.create(unitofworksource.getunitofworkfactory());         tcvm.save(transaction); 

and gives me error on variable tcvm when calling save function

system.nullreferenceexception unhandled user code   hresult=-2147467261   message=object reference not set instance of object.   source=devexpress.mvvm.v16.1.datamodel   stacktrace:        @ devexpress.mvvm.datamodel.repositoryextensions.<>c__displayclass1_0`3.<getprojectionprimarykey>b__0(tentity x)        @ devexpress.mvvm.datamodel.repositoryextensions.getprojectionvalue[tentity,tprojection,tentityresult,tprojectionresult](tprojection value, func`2 entityfunc, func`2 projectionfunc)        @ devexpress.mvvm.datamodel.repositoryextensions.getprojectionprimarykey[tentity,tprojection,tprimarykey](irepository`2 repository, tprojection projectionentity)        @ devexpress.mvvm.datamodel.repositoryextensions.findexistingoraddnewentity[tentity,tprojection,tprimarykey](irepository`2 repository, tprojection projectionentity, action`2 applyprojectionpropertiestoentity)        @ devexpress.mvvm.viewmodel.collectionviewmodelbase`4.save(tprojection projectionentity)        @ template.viewmodels.clientcollectionviewmodel..ctor(iunitofworkfactory`1 unitofworkfactory) in c:\users\edwin\source\workspaces\invasst\template\template\viewmodels\client\clientcollectionviewmodel.cs:line 37        @ clientcollectionviewmodel_97cd3897_6fb7_469b_9928_d61260161e61..ctor(iunitofworkfactory`1 unitofworkfactory)   innerexception:  

i'm using devexpress 16.1.5 , project using hybridapp template

... strategy instance of collectionviewmodel model , use save method sending object same model parameter.

i'm afraid strategy wrong. should use new() command provided corresponding collectionviewmodel (bound grid). real usage depends on specific needs. in simple case, can add button above grid , bind new command button.

related dx support thread : batch insert/ edit master/detail


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -