QueryableDataServiceCollectionView and Odata 2 Batch Transaction

5 posts, 0 answers
  1. Michael
    Michael avatar
    11 posts
    Member since:
    Oct 2013

    Posted 23 Dec 2014 Link to this post

    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.


  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Dec 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    11 posts
    Member since:
    Oct 2013

    Posted 29 Dec 2014 in reply to Dimitrina Link to this post

    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(). 

     
  5. Michael
    Michael avatar
    11 posts
    Member since:
    Oct 2013

    Posted 29 Dec 2014 in reply to Dimitrina Link to this post

    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().
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Dec 2014 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready