Cascading is created so that when you create a master record, you can create a new record associated with it. For example, after we create a customer record, we typically need to create a contact record and then set the contact record as the primary contact for that account record.
In the above example, if we do this in the traditional way, we need to request the server 3 times to complete, if the relevant record data involved, then the number of requests also need to increase. But if we use the cascading creation capabilities of the Web API, we only need to make one request to the server.
Cascading creation is consistent with the request for normal creation, and the only difference is how to construct the object to be recorded. We continue to use the example above, and we intend to create a customer record and create a record of the primary contact with which it manages, so this creation object is constructed as follows:
Jobject account = new Jobject (); Account. ADD ("Name", Stringgenerator (Numbergenerator ())); Jobject primarycontact = new Jobject (); Primarycontact.add ("LastName", Stringgenerator (Numbergenerator ())); Account. ADD ("Primarycontactid", primarycontact);
When everything is ready, we commit the object using the following C # code, so that we can complete the requirements of the last scenario description in a single request.
Httprequestmessage req = new Httprequestmessage (Httpmethod.post, "accounts"); Req. Content = new Stringcontent (Jsonconvert.serializeobject (account), Encoding.UTF8, "Application/json"); Httpresponsemessage resp = await _client. SendAsync (req);
Dynamics CRM 2015/2016/365 Web API: cascading creation