Would this do the same thing? But the dataservice will do it faster?
//Dataservice
using (var db = DataService.CreateBatch())
{
foreach (var variant in _variantsToUpdate)
{
db.Update(variant);
}
db.Commit();
}
// VariantService
foreach (var variant in _variantsToUpdate)
{
_variantService.Update(variant);
}
Litium version: 6
Yes, they are equal in what it will do.
The part that is different between them is that in the usage of data service everything is going in one transaction to the database and if something is failing for any variant no updates on any variants will occur.
When you using VariantService and iterating over the variants and update one by one. if any of them is failing the updates will stop and you will have some records that are updated and some that not are. Then you probably need to rerun all the updates to ensure that you have all data in correct state.
Is this correct? The dataservice will do it faster?
When you use the .Create
/.Update
/.Delete
methods on the service they are using the dataservice and the batch API for the database communication but each command will be sent separately to the database server. If using the batch API directly you can increase the performance because the commands can be batched together for multiple entities.