C
C#2y ago
Zil

❔ SQL query for multiple data objects

Hello folks, Imagine i have a json array of json objects that i send to an API wich uses a SQL query to INSERT the data into the database. Each json object in the array contains data that should be pushed into table 1. every json object also contains a property called parameters that is an Array of objects. each object of this parameters array needs to be inserted into table 2. Is it normal practice to for example loop over all parameters and execute the SQL query for each item? It feels wrong to do that somehow but then again i dont know what other option there is. Thanks in advance!
6 Replies
Nergy101
Nergy1012y ago
Normally you would create a Sql query that inserts many rows at once Or use some objects/classes/systems from your programming language
Zil
ZilOP2y ago
but in my case this can't be done right? I have this data structure:
[
{
data: 'ForTable1'
parameters: [
0: {
dataNested: 'ForTable2'
},
1: {
dataNested: 'ForTable2'
},
]
},
{
data: 'dataForTable1'
parameters: [
0: {
dataNested: 'ForTable2'
},
1: {
dataNested: 'ForTable2'
},
]
}
]
[
{
data: 'ForTable1'
parameters: [
0: {
dataNested: 'ForTable2'
},
1: {
dataNested: 'ForTable2'
},
]
},
{
data: 'dataForTable1'
parameters: [
0: {
dataNested: 'ForTable2'
},
1: {
dataNested: 'ForTable2'
},
]
}
]
Tvde1
Tvde12y ago
Why can't it be in one query?
Nergy101
Nergy1012y ago
it can, you'd loop over it and construct 1 SQL query string and then do that 1 sql query
Luc ♡
Luc ♡2y ago
EF Core would make your life way easier with this
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server