This is a migrated thread and some comments may be shown as answers.

QueryableDataServiceCollectionView and Odata 2 Batch Transaction

4 Answers 107 Views
DataServiceDataSource
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 23 Dec 2014, 02:00 PM
Environment: WPF,MVVM, Odata 2, EF6, MVC

Scenario: 

Attempting to submit a master/detail payload as a single transaction via a Telerik QueryableDataServiceCollectionView. Payload consists of 1 master record and 12 related detail records for insert.  

I have included the following code in WebApiConfig:

config.Routes.MapHttpBatchRoute(
        routeName: "WebApiBatch",
        routeTemplate: "api/$batch",
        batchHandler: new DefaultHttpBatchHandler(GlobalConfiguration.DefaultServer));

 and 

 config.Routes.MapODataRoute(
"odata",
"odata",
builder.GetEdmModel(),
batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));

Now on the Client side, I don't know how to tell the QueryableDataServiceCollectionView to transmit the payload as a single transaction when SubmitChanges() is called.

ViewModel Constructor:

this.odataScoreService = odataScoreService;
odataScoreService.Service.SaveChangesDefaultOptions = SaveChangesOptions.Batch;

ProjectPhaseScores = new QueryableDataServiceCollectionView<ProjectPhaseScore>(odataScoreService.Service, odataScoreService.Entity);
ProjectPhaseScores.Expand = "ScoreItems";
ProjectPhaseScores.LoadedData += OnLoadedScoreData;
ProjectPhaseScores.FilterDescriptors.Add(projectPhaseFilterDescriptor);


I am still very new to Visual Studio Development so any assistance would be greatly appreciated.


4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 26 Dec 2014, 12:43 PM
Hi,

You can check the DataServiceDataSource example of a master-details implementation in our WPF Demos. This example follows the MVVM pattern and is using the QueryableDataServiceCollectionView<T> collection. This is actually the same collection that the RDSDS control is internally using and is designed to be used in MVVM scenarios. This is what I can suggest as it comes to our QueryableDataServiceCollectionView.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Michael
Top achievements
Rank 1
answered on 29 Dec 2014, 06:39 PM
Dimitrina,

Thank you for your response. 

My Master /Detail implementation works fine from a display perspective (Actually similar to the Demo that you suggested).  The problem is with the Save process. Currently when I save, a Post is issued for the master record  as well as 12 posts for each detail record.

I would like to send the entire graph back to the server as a single OData Post.  I believe I set up the Webapi and Odata Batch Routes correctly in WebApiConfig (I can provide the code if needed).

My Controller code is as follows:
public IHttpActionResult Post([FromBody] ProjectPhaseScore score)
    {
      if (!ModelState.IsValid)
      {
        return BadRequest(ModelState);
      }
       
      business.SaveGraph(score);
 
      return Created(score);
    }

I'm struggling with configuring the QueryableDataServiceCollectionView, so that it knows to issue a single Batch Post upon SubmitChanges(). 

 
0
Michael
Top achievements
Rank 1
answered on 29 Dec 2014, 06:53 PM
Dimitrina,

Thank you for the reply.

Displaying Master/Detail information is not my problem. My current setup is similar to the Demo that you suggested.

The problem is with the Save. Currently my Save issues a Post for a master record and 12 Posts for each detail record. I would like the Save to issue a single Post passing along the entire Master/Detail graph.

I have configured the WebapiConfig for Batch routing and adjusted my Controller Post method.

Controller Code:
public IHttpActionResult Post([FromBody] ProjectPhaseScore score)
    {
      if (!ModelState.IsValid)
      {
        return BadRequest(ModelState);
      }
       
      business.SaveGraph(score);
 
      return Created(score);
    }

I just don't know how to configure the QueryableDataServiceCollectionView to know issue a single Batch Post upon SubmitChanges().
0
Dimitrina
Telerik team
answered on 30 Dec 2014, 10:00 AM
Hello,

I am afraid there is not an option to configure QueryableDataServiceCollectionView like so.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DataServiceDataSource
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Michael
Top achievements
Rank 1
Share this question
or