Let's say I have the following data structure:
public class Account
{
public int AccountID { get; set; }
public string Name { get; set; }
}
public class Person
{
public int PersonID { get; set; }
public string Name { get; set; }
public List<Account> Accounts { get; set; }
}
I want to move my data from an SQL Server database to Azure Cosmos DB using a Data Factory. For each person, I want to create a json file containing the accounts as nested objects like this:
"PersonID": 1,
"Name": "Jim",
"Accounts": [{
"AccountID": 1,
"PersonID": 1,
"Name": "Home"
},
{
"AccountID": 2,
"PersonID": 1,
"Name": "Work"
}]
I wrote a stored procedure to retrieve my data. In order to include the accounts as nested objects, I convert the SQL query's result to json:
select (select *
from Person p join Account Accounts on Accounts.PersonID = p.PersonID
for json auto) as JsonResult
Unfortunately, my data gets copied into a single field instead of the proper object structure:
Does anyone know what I should do to fix this?
Edit There is a similar question here but I didn't find a good answer: Is there a way to insert a document with a nested array in Azure Data Factory?