Question

Adding multiple records on server side

Hi team. I have a business need to add multiple records to the same table on the server side during process execution. 

What is the best approach to do so? 

I was looking into EntitySchemaManager functionality but couln'd find solution myself. I am able to add one record at a time (see example below) but this proves to be ineficient aEntitySchemaManager approach. 

 

var entitySchema = _userConnection.EntitySchemaManager.GetInstanceByName("UsrTableName");
           var entity = entitySchema.CreateEntity(_userConnection);
           entity.SetDefColumnValues();
           entity.SetColumnValue("UsrColumn1Id", id);
           entity.SetColumnValue("UsrDate", date);
           entity.Save();

 

Please, advice.

Like 0

Like

3 comments

Hi Iuliia, 
You could probably use the "Add element" with "Add from selection" mode selected. It's hard to tell having so few details. If you could tell a bit more details it'd make it easier to suggest something. 
 

Hello Iuliia,
Thank you for your question,

It would be nice if you could provide more details regarding issue that you are facing: your code, business process etc.

Yevhenii Grytsiuk, Yurii Sokil,

the (simplified) business process is next: 

user creates some record in UsrTableName_1 that has StartDate and EndDate, usually they are far apart (for example, long leave of absence, that last up to few month). 

For reporting purposes we need to have these dates stored as separate records, meaning for each date between StartDate and EndDate we need to have separate record added to UsrTableName_2. 

To do so I am able to loop through dates  between StartDate and EndDate and add necessry records one by one (using the code snippet provided by me above) but it is ineficient approach because of the multiple Save calls. 

What I want to do is to calculate all the necesary records, add/attach them and then call Save() only once, so there would be only one call to the DB to write the data. All this should be implemented on backend. Essentially I am looking for similar functionality that is provided by EntityFramework where one can call context.SaveChanges() after adding all records to the context (here is example how EF works https://learn.microsoft.com/en-us/ef/core/saving/basic#multiple-operations-in-a-single-savechanges) 

Does such approach exist in creatio? 

Thanks

 

 

 

Show all comments